<template>
  <div v-if="addVisible" class="editpanelPop">
    <div class="editpanel  twoStageWindow" style="padding-bottom:0;" v-loading="loading">
      <div class="twoStageWindowTitle">
        数据修改 <span style="margin-left:8px;font-size:13px;">{{testEntryData.detectabilityName}}</span>
        <div class="twoStageWindowClose">
          <el-button size="mini" type="primary" v-on:click="submitEntery('commit')" :disabled="!isRepeat">提交</el-button>

          <!-- <el-button size="mini" type="primary" v-on:click="resultentry('save')" :disabled="!isRepeat">保存</el-button> -->
          <el-button size="mini" v-on:click="close">取消</el-button>
        </div>
      </div>
      <div class="containercontent" style="margin-top: 40px;height:calc(100% - 40px);padding:0 20px;" v-loading="loading1"
        element-loading-text="拼命加载中">
        <div>
          <div style="height:40px;line-height:40px;margin-bottom:10px;">
            <div class="resultControlBar">
              检测单信息

              <!--<el-button size="mini" type="primary" @click="editequipCheck">仪器使用前检查</el-button> || testEntryData.status == '532'-->
              <el-button size="mini" type="primary" @click="lookequipCheck">仪器使用记录</el-button>
              <form id="attachmentForm" style="display:inline-block">
              <input type="file" name="file" id="attachment" @change="attachment" multiple>
            </form>
              <el-button size="mini" type="primary" @click="uploadAttachment" style="margin-left:10px;">上传附件</el-button>
              <!--<el-button size="mini" type="primary" @click="getEuitpmentTemp">温控</el-button>-->
            </div>
          </div>
          <div id="aSinglBatch">
            <el-table :data="testEntryDetail" size="mini" style="width:100%;">
              <el-table-column prop="code" label="检测单号" show-overflow-tooltip></el-table-column>
              <el-table-column prop="equipmentName" label="主仪器" show-overflow-tooltip></el-table-column>
              <el-table-column prop="assistEquipmentName" label="辅助仪器" show-overflow-tooltip></el-table-column>
              <el-table-column prop="checkerName" label="校核人员" show-overflow-tooltip>
              </el-table-column>
              <el-table-column prop="togetherWithName" label="共同完成人"></el-table-column>
              <el-table-column prop="status" label="状态">
                <template slot-scope="scope">
                  <el-popover trigger="hover" placement="top" v-if="opinionList.length != 0">
                    <div v-for="(item,index) in opinionList" :key="index">
                      <p>【{{item.createTime.substring(0,16)}}】 {{item.trackOpinion}}</p>
                    </div>
                    <div slot="reference" class="name-wrapper">
                      <el-tag size="medium">{{ scope.row.statusName }}</el-tag>
                    </div>
                  </el-popover>
                  <div slot="reference" class="name-wrapper" v-if="opinionList.length == 0">
                    <el-tag size="medium">{{ scope.row.statusName }}</el-tag>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="desc" label="备注">
                <template slot-scope="scope">
                  <el-input size="mini" v-model="testEntryData.desc"></el-input>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <div style="padding:20px 0;height: calc(100% - 120px);">
          <div style="padding-bottom: 10px;height:32px;" id="yangpinceshibar">
            <div class="inlineblock" style="width:70px">样品测试</div>
            <div class="resultControlBar inlineblock" style="width:calc(100% - 80px)">
              <!-- <el-button size="mini" type="primary" @click="excelTemplet">导出模板</el-button> -->

              <!-- <form id="fileForm1" style="display:inline-block">
              <input type="file" name="file" id="file1" @change="upload1">
            </form>
            <el-button size="mini" type="primary" @click="uploadClick1">导入结果</el-button> -->

              <!-- <form id="fileForm" style="display:inline-block">
              <input type="file" name="file" id="file" @change="upload">
            </form>
            <el-button size="mini" type="primary" @click="uploadClick">上传结果</el-button>
            <el-button size="mini" type="primary" :disabled="multipleSelection.length == 0" @click="batchInput">批录入</el-button>

            <el-button :disabled="sampleSelection.length == 0" size="mini" type="primary" @click="resultVoid">无效结果</el-button>
            <el-button :disabled="multipleSelectionsLen == 0" size="mini" type="primary" @click="finshed">强制完成</el-button>
            <el-button :disabled="sampleSelection.length == 0" size="mini" type="primary" @click="initResult">初始化</el-button> -->
              <el-button size="mini" type="primary" @click="zhuisuShowClick">追溯</el-button>
              <el-button @click="changeView" size="mini" type="primary">切换视图</el-button>

              <!--部分能力参数不使用校准曲线则不显示次按钮-->
              <el-button size="mini" type="primary" @click="standarLine" v-if="testEntryData.doUseCurve">标准曲线</el-button>
              <el-button size="mini" type="primary" @click="titrationResult" v-if="titrationBtn">标定结果</el-button>

              <el-button size="mini" type="primary" @click="verifyQcData">质控验证</el-button>
            </div>
          </div>
          <!--{{resultTableData}}-->
          <div v-if="yuanshijiemian">
            <div class="inlineblock" style="width: calc(35% - 15px);vertical-align:top;" id="sampleTable">
              <el-table :data="testEntryData.sampleBeans" style="width: 100%" size="mini" ref="sampleTable" :height="sampleTableHeight"
                highlight-current-row @row-click="sampleTableCurrentChange" @selection-change="handleSampleChange"
                :row-style="rowStyle">
                <el-table-column fixed type="selection" toggleRowSelection width="38px" :selectable='selectInit'>
                </el-table-column>
                <el-table-column width="45px" fixed label="序号">
                  <template slot-scope="scope">
                    <el-popover trigger="hover" placement="bottom" effect="dark" v-if="scope.row.color != null">
                      <span>
                        <span>
                          {{scope.row.color == 1 ? '重录':(scope.row.color == 2 ? '重测':'重采')}}意见:
                        </span>
                        <span>
                          {{scope.row.opinion == null ? "无意见" : scope.row.opinion}}
                        </span>
                      </span>
                      <div slot="reference" class="name-wrapper">
                        {{scope.$index+1}}
                      </div>
                    </el-popover>
                    <div v-if="scope.row.color == null">
                      {{scope.$index+1}}
                    </div>

                  </template>
                </el-table-column>
                <el-table-column property="sampleCode" label="样品编号" fixed min-width="110px" show-overflow-tooltip>
                  <template slot-scope="scope">
                    <el-popover trigger="hover" placement="bottom" effect="dark" v-if="scope.row.color != null">
                      <span>
                        <span>
                          {{scope.row.color == 1 ? '重录':(scope.row.color == 2 ? '重测':'重采')}}意见:
                        </span>
                        <span>
                          {{scope.row.opinion == null ? "无意见" : scope.row.opinion}}
                        </span>
                      </span>
                      <div slot="reference" class="name-wrapper">
                        {{ scope.row.sampleCode}}
                      </div>
                    </el-popover>
                    <div v-if="scope.row.color == null">
                      {{ scope.row.sampleCode}}
                    </div>
                  </template>
                </el-table-column>
                <el-table-column property="sampleName" label="样品名称" min-width="140px" show-overflow-tooltip>
                  <template slot-scope="scope">
                    <el-popover trigger="hover" placement="bottom" effect="dark" v-if="scope.row.color != null">
                      <span>
                        <span>
                          {{scope.row.color == 1 ? '重录':(scope.row.color == 2 ? '重测':'重采')}}意见:
                        </span>
                        <span>
                          {{scope.row.opinion == null ? "无意见" : scope.row.opinion}}
                        </span>
                      </span>
                      <div slot="reference" class="name-wrapper">
                        {{scope.row.doBlind ? '***':scope.row.sampleName}}
                      </div>
                    </el-popover>
                    <div v-if="scope.row.color == null">
                      {{scope.row.doBlind ? '***':scope.row.sampleName}}
                    </div>
                  </template>
                </el-table-column>

                <el-table-column property="taskName" label="任务名称" min-width="140px" show-overflow-tooltip>
                  <template slot-scope="scope">
                    <el-popover trigger="hover" placement="bottom" effect="dark" v-if="scope.row.color != null">
                      <span>
                        <span>
                          {{scope.row.color == 1 ? '重录':(scope.row.color == 2 ? '重测':'重采')}}意见:
                        </span>
                        <span>
                          {{scope.row.opinion == null ? "无意见" : scope.row.opinion}}
                        </span>
                      </span>
                      <div slot="reference" class="name-wrapper">
                        {{scope.row.taskName == null ? "---":scope.row.taskName}}
                      </div>
                    </el-popover>
                    <div v-if="scope.row.color == null">
                      {{scope.row.taskName == null ? "---":scope.row.taskName}}
                    </div>
                  </template>
                </el-table-column>
                <el-table-column property="factDate" label="采样日期" width="115px">
                  <template slot-scope="scope">
                      {{scope.row.factDate == null || scope.row.factDate == "" || scope.row.factDate == undefined? "---":scope.row.factDate.split(" ")[0]}}
                  </template>
                </el-table-column>
                <el-table-column property="qcTypeName" width="120px" label="QC类型" :formatter="formatterQcType"
                  show-overflow-tooltip>
                  <template slot-scope="scope">
                    <el-popover trigger="hover" placement="bottom" effect="dark" v-if="scope.row.color != null">
                      <span>
                        <span>
                          {{scope.row.color == 1 ? '重录':(scope.row.color == 2 ? '重测':'重采')}}意见:
                        </span>
                        <span>
                          {{scope.row.opinion == null ? "无意见" : scope.row.opinion}}
                        </span>
                      </span>
                      <div slot="reference" class="name-wrapper">
                        {{scope.row.doBlind ? '***':scope.row.qcTypeName}}
                      </div>
                    </el-popover>
                    <div v-if="scope.row.color == null">
                      {{scope.row.doBlind ? '***':scope.row.qcTypeName}}
                    </div>

                  </template>
                </el-table-column>
                <el-table-column property="parentCode" label="父样编号" width="115px" show-overflow-tooltip>
                  <template slot-scope="scope">
                    <el-popover trigger="hover" placement="bottom" effect="dark" v-if="scope.row.color != null">
                      <span>
                        <span>
                          {{scope.row.color == 1 ? '重录':(scope.row.color == 2 ? '重测':'重采')}}意见:
                        </span>
                        <span>
                          {{scope.row.opinion == null ? "无意见" : scope.row.opinion}}
                        </span>
                      </span>
                      <div slot="reference" class="name-wrapper">
                        {{scope.row.doBlind ? '***':scope.row.parentCode}}
                      </div>
                    </el-popover>
                    <div v-if="scope.row.color == null">
                      {{scope.row.doBlind ? '***':scope.row.parentCode}}
                    </div>

                  </template>
                </el-table-column>
                <el-table-column property="subcontractorName" label="分包商" v-if="testEntryData.doSub"
                  :show-overflow-tooltip="true">
                  <template slot-scope="scope">
                    <el-popover trigger="hover" placement="bottom" effect="dark" v-if="scope.row.color != null">
                      <span>
                        <span>
                          {{scope.row.color == 1 ? '重录':(scope.row.color == 2 ? '重测':'重采')}}意见:
                        </span>
                        <span>
                          {{scope.row.opinion == null ? "无意见" : scope.row.opinion}}
                        </span>
                      </span>
                      <div slot="reference" class="name-wrapper">
                        {{scope.row.doBlind ? '***':scope.row.subcontractorName}}
                      </div>
                    </el-popover>
                    <div v-if="scope.row.color == null">
                      {{scope.row.doBlind ? '***':scope.row.subcontractorName}}
                    </div>

                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div class="inlineblock" style="width:65%;margin-left:10px;">
              <el-table ref="fenxixiangTable" :data="resultTableData" style="width: 100%" size="mini" :height="sampleTableHeight"
                class="tableCon" highlight-current-row @current-change="resultTableCurrentChange" @selection-change="handleSelectionChange"
                key="2" v-if="reload" @cell-mouse-enter="cellMouseEnter">
                <el-table-column type="selection" width="38px" :selectable='selectItem'>
                </el-table-column>
                <el-table-column label="项目名称" prop="resultMap.itemName" min-width="100px" show-overflow-tooltip>
                  <template slot-scope="scope">
                    <el-popover trigger="hover" placement="bottom" effect="dark" v-if="scope.row.formulaAlias != null">
                      <p>{{scope.row.formulaAlias}}</p>
                      <div slot="reference" class="name-wrapper">
                        {{scope.row.itemName != '' && scope.row.itemName != undefined ? scope.row.itemName:scope.row.analysisName}}
                      </div>
                    </el-popover>
                    <div v-if="scope.row.formulaAlias == null">
                      {{scope.row.itemName != '' && scope.row.itemName != undefined ? scope.row.itemName:scope.row.analysisName}}
                    </div>
                    <!--{{scope.row.itemName != '' && scope.row.itemName != undefined ? scope.row.itemName:scope.row.analysisName}}-->
                  </template>
                </el-table-column>
                <template v-for="(col,index) in resultTableTitle">

                  <el-table-column :label="col.normName" :prop="col.normCode" :key="col.normCode" min-width="120px"
                    show-overflow-tooltip v-if="col.inputType == 1 && col.doDisplay">
                    <template slot-scope="scope">
                      {{scope.row.resultMap[col.normCode].value}}
                    </template>
                  </el-table-column>

                  <el-table-column :label="col.normName" :property="col.normCode" :key="col.normCode" v-if="col.inputType == 2 && col.doDisplay">
                    <template slot-scope="scope">
                      <!--数字型显示输入框 只能输入汉字-->
                      <el-input size="mini" v-model="scope.row.resultMap[col.normCode].value" @blur="watchRes(scope.row.resultMap,col.normCode,scope.row)"
                        :disabled="!sampleRejectFlag" v-if="isDisabled(scope.row,col.normCode) && scope.row.dataType == 'DT001'"
                        @keyup.enter.native="watchRes(scope.row.resultMap, col.normCode,scope.row)"></el-input>
                      <!--文本框-->
                      <el-autocomplete class="inline-input" v-model="scope.row.resultMap[col.normCode].value" @blur="watchRes(scope.row.resultMap,col.normCode,scope.row)"
                        :disabled="!sampleRejectFlag" v-if="col.normCode == 'RES001' && isDisabled(scope.row,col.normCode) && scope.row.dataType == 'DT002'"
                        :fetch-suggestions="querySearch" size="mini" placeholder="请输入内容" :trigger-on-focus="false"></el-autocomplete>
                      <el-input size="mini" v-model="scope.row.resultMap[col.normCode].value" @blur="watchRes(scope.row.resultMap,col.normCode,scope.row)"
                        :disabled="!sampleRejectFlag" v-if="col.normCode != 'RES001' && isDisabled(scope.row,col.normCode) && scope.row.dataType == 'DT002'"
                        @keyup.enter.native="watchRes(scope.row.resultMap, col.normCode,scope.row)"></el-input>

                      <!--报出结果和方法检出限不可编辑-->
                      <span v-if="!isDisabled(scope.row,col.normCode)">{{scope.row.resultMap[col.normCode].value}}</span>

                    </template>
                  </el-table-column>
                  <el-table-column :label="col.normName" :prop="col.normCode" :key="Math.random()" v-if="col.inputType == 3 && col.doDisplay"
                    :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                      {{scope.row.resultMap[col.normCode].value}}
                    </template>
                  </el-table-column>
                </template>
              </el-table>
            </div>
          </div>
          <div v-if="!yuanshijiemian">
            <tongyong :testpanelData="testpanelData" :yuanshijiemian="yuanshijiemian"></tongyong>
          </div>
        </div>
      </div>

    </div>
    <!--{{zhuisuShow}}-->
    <zhuisu :addVisible.sync="zhuisuShow" :testpanelData="testpanelData"></zhuisu>
    <verifyQc :addVisible.sync="verifyQcshow" :testpanelData="testpanelData"></verifyQc>

    <!--<zhuisuTest :zhuisuShow.sync="zhuisuShow" ></zhuisuTest> -->
    <!-- <equip-check :addVisible.sync="equipCheckShow" :equipmenstId="equipmentId" :testpanelData="testpanelData" :fromModel = "standarModel"  :editOrAdd="editOrAdd" :hasEquipUse="testEntryData.hasEquipUse" @hasEquipUseChange="changeHasEquip($event)"></equip-check> -->
    <user-record :addVisible.sync="equipCheckShow" :equipmentId="equipmentId" :testpanelData="testpanelData" :fromModel="'dataCheck'"></user-record>
    <!-- <titrationResult :addVisible.sync="titrationShow" :testEntryData = "testEntryData" :titrationList = "titrationList"></titrationResult> -->
    <titrationResultCheck :addVisible.sync="titrationShow" :testEntryData="testEntryData" :titrationData.sync="titrationData"></titrationResultCheck>
    <standar-series :addVisible.sync="standardseriesshow" :testpanelDetail="testpanelData" :newOrEdit="newOrEdit"
      :standardSeriesDetail="standardSeriesForm" :userData="userData" :allUnit="allUnit" :standarModel="standarModel"
      :signalObj="signalObj"></standar-series>
    <el-dialog :visible.sync="resultVoidShow" width="25%" :show-close='false' class="resultVoidDialog"
      :closeOnClickModal='false'>
      <span slot="title" class="dialog-title">
        请选择结果无效的原因
      </span>
      <el-radio-group v-model="resultVoidValue" class="radioGroup">
        <el-radio label="1">无样</el-radio>
        <el-radio label="2">干扰</el-radio>
        <el-radio label="3">瓶坏</el-radio>
        <el-radio label="4">不测</el-radio>
      </el-radio-group>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" size="mini" @click="subResultVoid">确 定</el-button>
        <el-button size="mini" @click="closeResultVoid">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import {
    mapState
  } from 'vuex'
  // let math = require('mathjs');
  const tongyong = () => import('./tongyong.vue');
  const zhuisu = () => import('./zhuisu.vue');
  const verifyQc = () => import('./verifyQc.vue');
  const userRecord = () => import('./equipCheck.vue');
  const standarSeries = () => import('./standarSeries.vue');

  const titrationResultCheck = () => import('./titrationResultCheck.vue');
  export default {
    data() {

      return {
        testEntryData: {}, //数据录入信息
        initTestpanelData: {}, //初始化数据
        testEntryDetail: [], //检测单信息数据
        // resultTableTitle:[], //根据左侧qc类型不同，右边渲染不同的表
        resultShow: false,
        equipCheckShow: false, //仪器使用前检查
        resultTableData: [], //右边表数据
        equipmentId: null, //仪器id
        resultVoidShow: false, //强制完成原因
        resultVoidValue: null, //强制完成选中值
        reload: true,
        selectRow: {}, //当前选中的样品行

        resultTableTitle: [], //点击的样品要显示的标题
        resultTableTitleAll: [], //所有标题
        resultTableTitleSatndar: [], //qcType为undefined的表头
        allUnit: [], //所有的单位
        userData: [], //所有用户
        multipleSelection: [], //选中的分析项或者检测项
        sampleSelection: [], //选中的样品
        multipleSelections: [], //右边选中的检测项和分析项总和[0:[],1:[]]
        multipleSelectionsLen: 0, //multipleSelections的长度
        multipleSelecInd: 0, //左边当前选择的坐标

        sampleAndItemSelection: [], //选中的样品以及下面的分析项
        firstSampleId: null, //数据录入样品测试表中第一个样品的qcType
        sampleRejectFlag: true, //当前选中的样品审核状态
        zhuisuShow: false, //追溯
        standardseriesshow: false, //标准曲线
        verifyQcshow: false, //质控验证
        editOrAdd: 'edit', //新增还是编辑仪器使用记录
        standardSeriesForm: {
          code: '',
          configDate: null,
          temperature: '',
          humcodeity: '',
          doUse: false,
          checker: '',
          configMan: JSON.parse(sessionStorage.getItem('laboratoryAccountInfo')).loginid,
        },
        newOrEdit: "edit", //查看标准系列
        standarModel: "dataEntry", //数据模块的标准系列弹框
        standardArr: [], //标准系列样品数组
        signalObj: {}, //曲线图谱信号值
        sampleBeans: [],
        noParentQcType: [], //无父样的qc类型
        isRepeat: true,
        reslultMapRES: [], //当前表的reslultMap
        enterFlag: false,
        blankSum: 0,
        curveNum: false, //控制曲线弹框次数
        allItemAndAnalysis: [],
        loading: false,
        receptModuleId: "",
        showFaulmCount: false, //控制公式未被解析的次数
        setIntervalTimes: null, //每隔10秒保存一次
        indoorParallel: [], //室内平行样的code
        isSuccess: true, //定时保存接口请求成功之后再保存
        isCuvre: false, //是否调接口计算a,b
        loading1: true,
        equiptempShow: false,
        titrationShow: false, //标定结果
        titrationList: [], //标定结果表头的值
        equipArr: [], //该检测单的主仪器和所有辅助仪器
        opinionList: [], //驳回意见
        titrationBtn: true, //滴定分析项按钮
        titrationData: {},
        clickSample:{},

        resultTableCurrent: '',

        yuanshijiemian: true,
        isNd:'ND', // 原始结果可以输入ND
      }
    },
    computed: {
      ...mapState(['testBatchStatus', 'typeQcSelect', 'submitType', 'ruleSelect']),
      sampleTableHeight() {
        return ((window.innerHeight - 310))
      },

    },
    components: {
      tongyong,
      zhuisu,
      userRecord,
      standarSeries,
      titrationResultCheck,
      verifyQc
    },
    props: ['addVisible', 'testpanelData','selectData'],
    mounted() {
      this.$store.dispatch('dogetDictionary')

    },
    watch: {

      enterFlag(val) { //监听enterFlag变量按enter键和鼠标移走时候值变化，变化后重新计算值
        // 先算当前点击的公式
        for (var j in this.clickSample.analysisBeans) {
          this.blurInput(this.clickSample, this.clickSample.analysisBeans[j])
        }
        for (var j in this.clickSample.itemBeans) {
          this.blurInput(this.clickSample, this.clickSample.itemBeans[j])
        }
        this.curveNum = true;
        this.coefficient();
        for (var i in this.testEntryData.sampleBeans) {
          for (var j in this.testEntryData.sampleBeans[i].analysisBeans) {
            this.blurInput(this.testEntryData.sampleBeans[i], this.testEntryData.sampleBeans[i].analysisBeans[j])
          }

          for (var j in this.testEntryData.sampleBeans[i].itemBeans) {
            this.blurInput(this.testEntryData.sampleBeans[i], this.testEntryData.sampleBeans[i].itemBeans[j])
          }
        }

      },
      addVisible(val){
        if (val) {
          this.loading1 = true;
           this.testEntryData = {}
        }
      },
      testpanelData(val, oldVal) {
        if (val) {

          if(this.selectData.id != this.testpanelData.id){
            return;
          }
          this.loading1 = false;

          // 调用公共函数 传 数据校核 的模块路由取对应的模块id
          this.receptModuleId = this.util.getModuleId({
            module: "mygroupcheck"
          })
          this.userInfo = JSON.parse(sessionStorage.getItem('laboratoryAccountInfo')); //获取存储的用户信息
          // 初始化数据
          this.testEntryData = this.testpanelData;

          this.getOpinion(); //获取驳回意见

          this.getCalib(); //标定结果的表头 判断是否出现按钮
          this.sampleBeans = this.testEntryData.sampleBeans;
          if (this.testEntryData.curveBean == undefined || this.testEntryData.curveBean == null) {
            this.testEntryData.curveBean = {};
          }
          this.equipmentId = this.testEntryData.equipment; //仪器id
          this.testEntryDetail = [];
          // 组装检测单信息
          for (var i in this.testEntryData) {
            var obj = {};
            obj.code = this.testEntryData.code;
            obj.status = this.testEntryData.status;
            obj.statusName = this.formatterStatus(obj.status)
            obj.equipmentName = this.testEntryData.equipmentName;
            obj.assistEquipmentName = this.testEntryData.assistEquipmentName;
            obj.checkerName = this.testEntryData.checkerName;
            obj.togetherWithName = this.testEntryData.togetherWithName;
          }
          this.testEntryDetail.push(obj)




          // 调用表头数据函数
          this.readQcTypesInfo(); //质控不是标样，既qcType ！= undefined调用的接口

          this.readQcNorms(); //质控是标样  既qcType = undefined调用的接口
          this.readAllUnit();
          this.readUser();

          this.setCurrent(this.testEntryData.sampleBeans[0]) //设置检测单弹出，默认显示第一条样品的数据,并高亮显示

          //处理统计标准系列样品
          for (var i in this.testEntryData.sampleBeans) {
            if (this.testEntryData.sampleBeans[i].doStandard) {
              //1）获取标准系列样品的名字截取std，并为每个分析项加一个std属性--值为std1....
              var std = this.testEntryData.sampleBeans[i].sampleName.replace(/标准系列/g, ''); //改样品的std
              this.standardArr.push(this.testEntryData.sampleBeans[i])
              for (var j in this.testEntryData.sampleBeans[i].analysisBeans) {
                this.testEntryData.sampleBeans[i].analysisBeans[j].std = std;
                //2）获取标准系列样品中分析项的信号值
                if (this.testEntryData.sampleBeans[i].analysisBeans[j].analysisType == 1) {
                  // if (this.testEntryData.sampleBeans[i].analysisBeans[j].resultMap.RES002 != null) {
                  //     this.signalObj[std] = this.testEntryData.sampleBeans[i].analysisBeans[j].resultMap.RES002
                  // }
                  // console.log(this.signalObj)
                  // 3）获取标准系列样品中的曲线分析项，和seriesBeans对比，如果曲线分析项的std和seriesBeans的seriesSort相同
                  //标准系列样品中的曲线分析项的标准系列浓度值为相同这一条的seriesConcen
                  for (var k in this.testEntryData.seriesBeans) {
                    if (this.testEntryData.seriesBeans[k].seriesSort == std) {
                      this.testEntryData.sampleBeans[i].analysisBeans[j].resultMap.NORM006.value = this.testEntryData.seriesBeans[
                        k].seriesConcen
                    }
                  }
                }
              }
            }
            for (var j in this.testEntryData.sampleBeans[i].itemBeans) { //检测项的方法检出限 值为 检测项的detectionLimit,检测项的单位RES003值为unitName
              this.testEntryData.sampleBeans[i].itemBeans[j].resultMap.RES004.value = this.testEntryData.sampleBeans[i]
                .itemBeans[j].low;
              this.testEntryData.sampleBeans[i].itemBeans[j].resultMap.RES003.value = this.testEntryData.sampleBeans[i]
                .itemBeans[j].unitName;
            }
            for (var j in this.testEntryData.sampleBeans[i].analysisBeans) { //分析项的单位RES003值为unitName
              this.testEntryData.sampleBeans[i].analysisBeans[j].resultMap.RES003.value = this.testEntryData.sampleBeans[
                i].analysisBeans[j].unitName;
              // 进入页面时 分析项的原始结果是该分析的默认值
              var defaultValue = this.testEntryData.sampleBeans[i].analysisBeans[j].defaultValue
              if (!this.stringNotEmpty(this.testEntryData.sampleBeans[i].analysisBeans[j].resultMap.RES001) &&
                defaultValue != null && defaultValue != "" && defaultValue != undefined) {

                this.testEntryData.sampleBeans[i].analysisBeans[j].resultMap.RES001.value = this.testEntryData.sampleBeans[
                  i].analysisBeans[j].defaultValue;
                this.testEntryData.sampleBeans[i].analysisBeans[j].resultMap.RES002.value = this.decimal(this.testEntryData
                  .sampleBeans[i].analysisBeans[j].decimalRule, this.testEntryData.sampleBeans[i].analysisBeans[j].decimalNumber,
                  this.testEntryData.sampleBeans[i].analysisBeans[j].resultMap.RES001.value)

              }
            }
          }
          // 给每个样品的检测项和分析项加RES100属性 ,并且把所有样品的检测项和分析项存为一个数组
          for (var i in this.testEntryData.sampleBeans) {

            for (var j in this.testEntryData.sampleBeans[i].analysisBeans) {
              this.allItemAndAnalysis.push(this.testEntryData.sampleBeans[i].analysisBeans[j])
              this.testEntryData.sampleBeans[i].analysisBeans[j].resultMap.DEF100 = {
                value: null
              };
            }
            for (var j in this.testEntryData.sampleBeans[i].itemBeans) {

              this.allItemAndAnalysis.push(this.testEntryData.sampleBeans[i].itemBeans[j])
              this.testEntryData.sampleBeans[i].itemBeans[j].resultMap.DEF100 = {
                value: null
              };
            }
          }
          this.initTestpanelData = JSON.parse(JSON.stringify(this.testEntryData)); //深赋值数值，便于初始化按钮赋值
          var that = this;

        }
      },

    },
    methods: {
      // 获取驳回意见
      getOpinion() {
        this.$http({
          method: 'post',
          apiUrl: '/detection/getBatchOpinions.htm',
          params: {
            batch: this.testEntryData.id
          },
          isJson: false
        }).then(res => {
          if (res.code == 0) {
            this.opinionList = res.data;
          }
        })
      },
      // 计算a，b
      coefficient() {
        for (var i in this.testEntryData.sampleBeans) {
          for (var j in this.testEntryData.sampleBeans[i].analysisBeans) {
            var analysis = this.testEntryData.sampleBeans[i].analysisBeans[j];
            if (analysis.std != undefined && analysis.analysisType == 1) { //row.std !=undefined代表父样品不是标准系列样品,analysisType = 1代表 曲线分析项
              if (analysis.resultMap.RES001.value == '/') {
                this.signalObj[analysis.std] = '/'
              } else { //当输入值为'/'或者''的时候，则不加入信号值数组
                this.signalObj[analysis.std] = analysis.resultMap.RES001.value;
              }
            }
          }
        }
        var signalArr = Object.keys(this.signalObj); //把this.signalObj转为数组
        var len = signalArr.length; //取数组的长度,如果两个曲线分析项有值了 调用曲线斜率接口
        var xy = this.makeCoefficientData(this.signalObj); //拼接计算斜率需要的数据

        if (len >= 2) {
          this.getCoefficient(xy.x, xy.y);
        }

      },
      isDisabled(row, code) {
        var flag = false;

        //1.控制列是否可以编辑输入
        if (code == "RES001") { //原始结果可编辑
          flag = true;
        }
        if (code == "NORM011") { //取标样体积可编辑
          flag = true;
        }
        if (code == "NORM012") { //取样品体积可编辑
          flag = true;
        }
        if (code == "NORM013") { //其他体积可编辑
          flag = true;
        }
        // if (code == "NORM006") { //标准系列浓度可编辑
        //     flag = true;
        // }
        if (code == "NORM010") { //加标标样浓度可编辑
          flag = true;
        }
        //2.有公式的
        if ((row.formula != null && row.formula != "" && row.formula != undefined) && code == "RES001") { //如果该行有公式 原始结果不可编辑
          flag = false;
        }
        //3.分析项目只能编辑原始结果,其他不能编辑
        if (row.analysisCode !== undefined && code != "RES001") {
          flag = false;
        }
        //4.如果师分包批次 原始结果可编辑
        if (this.testEntryData.doSub) {
          if (code == "RES001") { //原始结果可编辑
            flag = true;
          }
        }
        return flag;
      },
      // 输入框是文本时调用提示数据的方法
      querySearch(queryString, cb) {
        this.getStandardString().then(res => {
          var standardString = [] //把接口返回的数据组装成为一个数组
          for (var i in res.data) {
            var obj = {};
            obj.value = res.data[i]
            standardString.push(obj)
          }
          var results = queryString ? standardString.filter(this.createFilter(queryString)) : standardString;
          // 调用 callback 返回建议列表的数据
          cb(results);
        })

      },
      createFilter(queryString) {
        return (restaurant) => {
          return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
        };
      },
      // 提示的数据
      getStandardString() {
        return new Promise((resolve, reject) => {
          this.$http({
            method: 'post',
            apiUrl: '/technology/getStandardString.htm',
          }).then(res => {
            if (res.code == 0) {
              resolve(res)

            }
          })
        })

      },

      // 追溯窗口弹出事件
      zhuisuShowClick() {
        this.zhuisuShow = true
      },
      verifyQcData() {
        this.verifyQcshow = true;

      },
      changeHasEquip(msg) {
        this.testEntryData.hasEquipUse = msg;
      },
      // 处理状态
      formatterStatus(cellValue) {
        return this.util.changeStatus({
          cellValue: cellValue,
          list: this.testBatchStatus
        })
      },
      // qc类型
      formatterQcType(row, column, cellValue, index) {
        return this.util.codeChangeName({
          cellValue: cellValue,
          list: this.typeQcSelect.itemList
        })
      },
      //默认选中第一条样品
      setCurrent(row) {
        this.$nextTick(() => {
          this.$refs.sampleTable.setCurrentRow(row);
          this.initTitle(this.testEntryData.sampleBeans[0].qcType) //设置检测单弹出，默认显示第一条样品的表头
          this.clickRow(this.testEntryData.sampleBeans[0], 0);
        })
      },
      // 读取单位
      readAllUnit(item) {
        this.allUnit = [];
        this.$http({
          method: 'post',
          apiUrl: '/technology/readLabUnitList.htm',
          params: {
            ename: item
          },
          isJson: true
        }).then(res => {
          if (res.code == 0) {
            this.allUnit = res.data;
          }
        })
      },
      // 读取用户
      readUser(item) {
        this.$http({
          method: 'post',
          apiUrl: '/resource/readEmployeeByLab.htm',
          params: {
            name: item
          },
          isJson: true,
        }).then(res => {
          if (res.code === 0) {
            this.userData = res.data;

          }

        })
      },
      // 样品测试每一行点击事件
      sampleTableCurrentChange(row, column, event) {
        this.resultTableTitle = [];
        this.clickSample = row;
        this.handleTitle(row.qcType); //渲染表头
        this.testEntryData.sampleBeans.forEach((item, index) => {
          if (item.sample == row.sample) {
            this.clickRow(row, index)
          }
        })

      },
      clickRow(row, index) {
        //
        this.multipleSelecInd = index;
        this.selectRow = row; //当前选中的行

        this.sampleRejectFlag = true;
        if (row.rejectFlag == 2 || row.rejectFlag == 3) { //如果改样品的驳回原因不是重录  则不可编辑
          this.sampleRejectFlag = false;
        }
        this.resultTableData = [];
        for (var i in row.analysisBeans) { //遍历分析项，resultMap的值和标题对应起来之后赋值
          this.resultTableData.push(row.analysisBeans[i])
        }
        // 该点击样品下的表是分析项和检测项目，检测项目在最下面，分析项在上面
        for (var i in row.itemBeans) {
          this.resultTableData.push(row.itemBeans[i])
        }
        for (var i in this.resultTableData) {
          this.reslultMapRES.push(this.resultTableData[i].resultMap)
        }
        var that = this;
        this.reLoad();
        setTimeout(function() {
          that.toggleSelection1(that.multipleSelections[index]);
        }, 100)
        this.showFaulmCount = true; // 点击每个样品，触发是否弹框（公式未被解析的弹框）
        this.enterFlag = !this.enterFlag

      },
      selectInit(row, index) { //判断样品列表是否可勾选 如果驳回意见不是重录（1） 则不可勾选
        if (row.rejectFlag == 2 || row.rejectFlag == 3) {
          return false //不可勾选
        } else {
          return true //可勾选
        }
      },
      selectItem(row, index) { //如果sampleRejectFlag为false  检测项和分析项列表也不可勾选
        if (!this.sampleRejectFlag) {
          return false //不可勾选
        } else {
          return true
        }
      },
      // 选中单位之后重加载 回填
      changeUnit(val) {
        this.reLoad();
      },

      basePath() {
        var curWwwPath = window.document.location.href;
        var pathName = window.document.location.pathname;
        var pos = curWwwPath.indexOf(pathName)
        var localhostPath = curWwwPath.substring(0, pos);
        var basePath = localhostPath + "/";
        return basePath;
      },

      // 获取所有的表头数据
      readQcTypesInfo() {
        // this.$http({
        //   method: 'post',
        //   apiUrl: '/qc/readQcTypesInfo.htm',
        // }).then(res => {
        //   if (res.code == 0) {
        //     this.resultTableTitleAll = res.data;
        //     for (var i in res.data) {
        //       //
        //       if (res.data[i].genre == "QCA01" || res.data[i].genre == "QCB01") {
        //         this.noParentQcType.push(res.data[i])
        //       }
        //       if(res.data[i].type == 2 && res.data[i].space == 2){ //找的室内平行样品
        //         // console.log(res.data[i].code)
        //         this.indoorParallel = res.data[i].code

        //       }
        //     }
        //   }
        // })
        var that = this;
        var url = null
        var path = this.basePath()
        if (process.env.NODE_ENV == 'development') { //本地
          url = 'laboratory/qc/readQcTypesInfo.htm'
        } else {
          url = path + 'laboratory/qc/readQcTypesInfo.htm'
        }

        this.$commitHttp(url, {}, {
          success: function(data) {
            if (data.code === 0) {
              that.resultTableTitleAll = data.data;
              that.indoorParallel = []
              for (var i in data.data) {
                if (data.data[i].genre == "QCA01" || data.data[i].genre == "QCB01") {
                  that.noParentQcType.push(data.data[i])
                }
                if (data.data[i].type == 2 && data.data[i].space == 2) { //找的室内平行样品
                  that.indoorParallel.push(data.data[i].code)
                }
              }
              console.log(that.indoorParallel)
            }
          }
        }, false)
      },

      // 是否重新加载
      reLoad() {
        this.reload = false;
        this.$nextTick(() => {
          this.reload = true;
        })
      },
      // 获取普通样的表头数据
      readQcNorms() {
        this.$http({
          method: 'post',
          apiUrl: '/qc/readQcNorms.htm',
          params: {
            genre: 1,
          },
          isJson: false
        }).then(res => {
          if (res.code === 0) {
            for (var i in res.data) {
              res.data[i].normCode = res.data[i].code
              res.data[i].normName = res.data[i].name
              res.data[i].doDisplay = true;
            }
            this.resultTableTitleSatndar = res.data;
          }

        })
      },
      // 根据qcType处理表头数据
      handleTitle(qctype) {
        if (qctype == undefined || qctype == null || qctype == '') {
          this.resultTableTitle = this.resultTableTitleSatndar;
        } else {
          for (var i in this.resultTableTitleAll) {
            if (qctype == this.resultTableTitleAll[i].code) {
              this.resultTableTitle = this.resultTableTitleAll[i].typeNormBeans;
            }
          }
        }
        // 如果该批次是分包样品，表头是普通样品的表头
        if (this.testEntryData.doSub) {
          this.resultTableTitle = this.resultTableTitleSatndar;
        }
      },
      // 进入页面显示第一行样品表头
      initTitle(qctype) {

        var tempArr = null;
        if (qctype == undefined || qctype == null || qctype == '') {
          this.$http({
            method: 'post',
            apiUrl: '/qc/readQcNorms.htm',
            params: {
              genre: 1,
            },
            isJson: false
          }).then(res => {
            if (res.code === 0) {
              for (var i in res.data) {
                res.data[i].normCode = res.data[i].code
                res.data[i].normName = res.data[i].name
                res.data[i].doDisplay = true
              }
              this.resultTableTitle = res.data;
            }
          })
          // var that = this
          // this.$commitHttp('laboratory/qc/readQcNorms.htm',{genre: 1},{success : function(data) {
          //         if (data.code === 0) {
          //             for (var i in data.data) {
          //                 data.data[i].normCode = data.data[i].code
          //                 data.data[i].normName = data.data[i].name
          //                 data.data[i].doDisplay = true;
          //             }
          //             // that.resultTableTitle = data.data;
          //             // this.$set()
          //             tempArr = data.data;
          //         }
          //     }
          // },false)
          // return tempArr
        } else {
          this.$http({
            method: 'post',
            apiUrl: '/qc/readQcTypesInfo.htm',
          }).then(res => {
            if (res.code == 0) {
              for (var i in res.data) {
                if (qctype == res.data[i].code) {
                  this.resultTableTitle = res.data[i].typeNormBeans;
                }
              }
            }
          })
        }
        // 如果该批次是分包样品，表头是普通样品的表头
        if (this.testEntryData.doSub) {
          this.resultTableTitle = this.resultTableTitleSatndar;
        }

      },
      // 检测项和分析项的空格只能输入数字和/，如果不是则设置为空
      handleClick(a, b, row) {

        if (a[b].value === null || a[b].value === "") { //当前输入框值为空,就设置值为空
          this.$set(a[b], "value", null)
        }
        // if (row.analysisType == 1) { //如果该项目设定为曲线分析项,那么不能输入字符串
        //   if(isNaN(a[b].value)){
        //     this.$set(a[b], "value", null);
        //   }else{
        //     this.$set(a[b], "value", Number(a[b].value)+0);
        //   }

        // }
        if (row.dataType == 'DT001' || row.analysisType == 1) {
          if(row.analysisType == 1 && (a[b].value == '/' || a[b].value == this.isNd)) { //如果该项目设定为曲线分析项,那么不能输入字符串
            this.$set(a[b], "value", null);
            return;
          }
          if (a[b].value != '/' && isNaN(a[b].value)) { //如果该项目是数字型,那么不能输入字符串，可以是 ”/“
            if(a[b].value == this.isNd && a[b].normCode != "NORM011" && a[b].normCode != "NORM010" && a[b].normCode != "NORM012"){
              this.$set(a[b], "value", this.isNd);
            }else{
              this.$set(a[b], "value", null);
            }
            return;
          }
          if (a[b].value != '/' && !isNaN(a[b].value)) { //处理 001为1  1.00为1.00
            if (a[b].value != null) {
              var result = (a[b].value.toString()).indexOf(".");
              if (result != -1) { //判断是否存在小数点
                var arr = a[b].value.toString().split(".");
                var fuhao = '';
                if(arr[0].substring(0,1) == '-'){
                  arr[0] = arr[0].substr(1,arr[0].length)
                  fuhao = "-"
                }
                arr[0] = Number(arr[0]) + 0;
                arr[0] = fuhao + arr[0]
                if (arr[1] == "") { //如果小数点后面没有字符，去掉小数点 处理 1.=1
                  this.$set(a[b], "value", arr[0]);
                } else { //为了消除前面的0
                  this.$set(a[b], "value", arr[0] + "." + arr[1]);
                }

              } else {
                this.$set(a[b], "value", Number(a[b].value) + 0); //如果不存在小数点 直接转换为数字，消除前面的 0 ，001为1
              }
            }
          }
        }
        // if (row.dataType == 'DT001' && a[b].value != '/' && isNaN(a[b].value)) { //如果该项目设定为数字型,那么不能输入字符串,DT001  输入框为数字型 DT002 文本型
        //   this.$set(a[b], "value", null);
        // }
        // if (row.dataType == 'DT001' && a[b].value != '/' && isNaN(a[b].value)) { //如果是字符串(不包括'/')
        //     this.$set(a[b], "value", null);
        // }
      },
      cellMouseEnter(row) { //鼠标放在检测项目或者分析项上 显示该行公式去掉{}和，
        if (row.formulaAlias != undefined) {
          var value = row.formulaAlias.replace(/{/g, '');
          value = value.replace(/}/g, '');
          value = value.replace(/,/g, '');
          row.formulaAlias = value;
        }
      },

      watchRes(a, b, row) {
        this.handleClick(a, b, row);
        this.enterFlag = !this.enterFlag;

      },
      //DEF100 原始结果的值 主要用于计算公式
      //DEF101 子样的父样
      blurInput(sampleObj, row) { //原始结果列鼠标失去焦点事件;sampleObj 是遍历的样品;row是样品下的检测项和分析项
        //1.处理非常规输入问题
        if (row.resultMap.RES001.value === undefined || row.resultMap.RES001.value === null || row.resultMap.RES001.value === "") { //RES001原始结果输入为空的时候 赋值为null
          row.resultMap.RES001.value = null;
          row.resultMap.RES002.value = null;
          row.resultMap.DEF100.value = null;
        }
        if (row.resultMap.RES001.value == "/") { //RES001原始结果输入为/的时候 赋值为/
          row.resultMap.RES001.value = "/";
          row.resultMap.RES002.value = "/";
          row.resultMap.DEF100.value = "/";
        }

        //2.利用原始结果 修约计算 报出结果
        if (row.resultMap.RES001.value !== undefined && row.resultMap.RES001.value !== null && row.resultMap.RES001.value !== '') {
          row.resultMap.DEF100.value = row.resultMap.RES001.value; //DEF100为RES001的值，主要用于计算公式
          if (isNaN(row.resultMap.RES001.value) && row.dataType == "DT002") { //如果原始结果值为字符串,并且输入型为文本型 报出结果值为原始结果
            row.resultMap.RES002.value = row.resultMap.RES001.value;
          }else { //处理数字型
            if(row.analysisCode != undefined && row.analysisCode != null && row.analysisCode != '') { //处理分析项，直接修约
              row.resultMap.RES002.value = this.decimal(row.decimalRule, row.decimalNumber, row.resultMap.RES001.value);
            }else{ //检测项和下限或者检测限对比后再修约
              row.resultMap.RES002.value = this.decimal(row.decimalRule, row.decimalNumber, row.resultMap.RES001.value);//修约原始结果
              if (row.low != undefined && row.low != null && row.low != '') { //1）优先判断下限，只有下限
                if (row.resultMap.RES001.value < Number(row.low)) {
                  row.resultMap.RES002.value = "<" + row.low; //报出结果显示 <下限
                }
              }
              if ((row.low == undefined || row.low == null || row.low == '') && (row.detectionLimit != undefined && row.detectionLimit != null)) { //2）只有检出限
                if (row.resultMap.RES001.value < Number(row.detectionLimit)) {
                  row.resultMap.RES002.value = "<" + row.detectionLimit; // 报出结果显示 < 检出限
                }
              }
            }
          }
        }

        //3.收集标准系列样品的曲线信号值
        // console.log(row.std,row.analysisType)
        // 2019-9-04屏蔽  优化代码 减少调用接口次数
        // if (row.std != undefined && row.analysisType == 1) { //row.std !=undefined代表父样品不是标准系列样品,analysisType = 1代表 曲线分析项
        //   if (row.resultMap.RES001.value == '/') {
        //     this.signalObj[row.std] = '/'
        //   } else { //当输入值为'/'或者''的时候，则不加入信号值数组

        //     this.signalObj[row.std] = row.resultMap.RES001.value;
        //   }

        //   var signalArr = Object.keys(this.signalObj); //把this.signalObj转为数组
        //   console.log(this.signalObj)
        //   var len = signalArr.length; //取数组的长度,如果两个曲线分析项有值了 调用曲线斜率接口
        //   var xy = this.makeCoefficientData(this.signalObj); //拼接计算斜率需要的数据
        //   console.log(xy)
        //   if (len >= 2 && row.analysisType == 1) {
        //     this.getCoefficient(xy.x, xy.y);
        //   }
        // }

        //3.1.信号值分析项的截距,斜率,相关系数
        for (var i in this.standardArr) {
          for (var j in this.standardArr[i].analysisBeans) {
            if (this.standardArr[i].analysisBeans[j].analysisType == 1) {
              // NORM007 斜率  NORM008 截距 NORM009 相
              this.standardArr[i].analysisBeans[j].resultMap.NORM007.value = this.testEntryData.curveBean.slope
              this.standardArr[i].analysisBeans[j].resultMap.NORM008.value = this.testEntryData.curveBean.deviation
              this.standardArr[i].analysisBeans[j].resultMap.NORM009.value = this.testEntryData.curveBean.coefficent
            }
          }
        }

        //4.如果该检测单的能力参数需要使用标准曲线（doUseCurve）,就肯定会有两个室内空白样品,计算两个室内空白的报出结果的平均值，
        if (this.testEntryData.doUseCurve) { // 4.1） 主要用于计算平均值 -空白之和/2
          var arr = [];
          for (var i in this.testEntryData.sampleBeans) {
            //遍历所有样品，如果循环到的样品的parent和当前样品的parent相同，并且有qctype  代表遍历到的该样品为子样品
            if (this.testEntryData.sampleBeans[i].qcTypeName == "室内空白") {
              for (var j in this.testEntryData.sampleBeans[i].analysisBeans) {
                if (this.testEntryData.sampleBeans[i].analysisBeans[j].analysisType == 1) {
                  arr.push(Number(this.testEntryData.sampleBeans[i].analysisBeans[j].resultMap.RES001.value))
                  break;
                }
              }
            }
          }
          var m = 0;
          this.blankSum = 0;
          for (var i = 0; i < arr.length; i++) {
            if (arr[i] != null && arr[i] != '/') {
              this.blankSum = this.blankSum + arr[i]
              m++
            }
          }
          if (m != 0) {
            this.blankSum = Number(this.$math.eval(this.blankSum / m));
          }
        }

        // 5.检测项目与分析项目中  - 解析公式并计算
        this.countFormula(sampleObj)

        //6.添加双空白报出结果的计算值，并计算双空白的父样结果
        if (sampleObj.space == 2 && sampleObj.group == 2) { //若为 group:2 无父样 space:2室内 ；（空白A）
          for (var i in this.testEntryData.sampleBeans) {  //遍历所有样品
            var hasAnalysis = false;//遍历每个样品时,判断每个样品是否包含信号分析项
            var orgResult = null;  //原始结果
            var parResult = null; //父样结果
            //6.1 找到相同的QCtype但是不是本身的样品（空白B）
            if (this.testEntryData.sampleBeans[i].qcType == sampleObj.qcType && this.testEntryData.sampleBeans[i].id != sampleObj.id) {
              //6.2 遍历样品分析项
              for(var j in sampleObj.analysisBeans){
                  //6.2.1 如果有信号分析项，计算信号分析项的父样结果
                  if(sampleObj.analysisBeans[j].analysisType == 1 ){
                    for (var k in this.testEntryData.sampleBeans[i].analysisBeans) {//遍历空白B的分析项
                       if (this.testEntryData.sampleBeans[i].analysisBeans[k].resultMap.NORM001 !== undefined) {//保证该分析项有 父样结果 这个参数
                          if (this.testEntryData.sampleBeans[i].analysisBeans[k].analysisCode == sampleObj.analysisBeans[j].analysisCode) {//找到空白A 与 空白B 对应的分析项
                            hasAnalysis = true;
                            this.testEntryData.sampleBeans[i].analysisBeans[k].resultMap.NORM001.value = sampleObj.analysisBeans[j].resultMap.RES002.value;//空白B的父样结果 = 空白A的报出结果
                            orgResult = this.testEntryData.sampleBeans[i].analysisBeans[k].resultMap.RES001.value;
                            parResult = sampleObj.analysisBeans[j].resultMap.RES001.value;
                          }
                          sampleObj.analysisBeans[j].resultMap.DEF101 = {value:null};
                          sampleObj.analysisBeans[j].resultMap.DEF101.value = this.testEntryData.sampleBeans[i].analysisBeans[k].resultMap.RES001.value
                       }
                    }
                  }
              }
              //6.3 遍历样品的检测项
              for (var j in this.testEntryData.sampleBeans[i].itemBeans) { //遍历样品的检测项
                if (this.testEntryData.sampleBeans[i].itemBeans[j].resultMap.NORM001 !== undefined) {
                  for (var k in sampleObj.itemBeans) {
                     if(hasAnalysis){  //如果该项目有被标记该样品下有信号分析项，则使用信号分析项的原始结果和父样结果来计算相对偏差
                        this.$set(sampleObj.itemBeans[k],'hasAnalysis',true);
                        this.$set(sampleObj.itemBeans[k],'orgResult',orgResult)
                        this.$set(sampleObj.itemBeans[k],'parResult',parResult)
                      }
                      if (this.testEntryData.sampleBeans[i].itemBeans[j].itemCode == sampleObj.itemBeans[k].itemCode) {
                        this.testEntryData.sampleBeans[i].itemBeans[j].resultMap.NORM001.value = sampleObj.itemBeans[k].resultMap.RES002.value
                        // 子样的父样结果，用来计算相对偏差
                        this.testEntryData.sampleBeans[i].itemBeans[j].resultMap.DEF101 = {
                          value:null
                        }
                        //给父样样品加上字段DEF101，值为本样品的原始结果
                        this.testEntryData.sampleBeans[i].itemBeans[j].resultMap.DEF101.value = sampleObj.itemBeans[k].resultMap.RES001.value;
                      }
                  }
                }
              }
            }
          }
        }

        // 7. 计算有父样的质控样品（平行、加标）的父样结果  ； 指普通样品的报出结果 赋值给 子样品的父样结果
        var paral = 0;  // indoorParallel:定义计算室内平行的值
        if (sampleObj.parent != null && (sampleObj.qcType == null || sampleObj.qcType == '' || sampleObj.qcType == undefined)) { //有parent，并且qcType为null，代表该样品为父样
          var paralNum = 0; // indoorParallel:定义平行子样的个数
          //
          for(var i in sampleObj.itemBeans){
            this.$set(sampleObj.itemBeans[i],'totle',0)
          }
          for (var i in this.testEntryData.sampleBeans) {
            var isPaeall = false;  // indoorParallel:是否为平行样品
            //遍历所有样品，如果循环到的样品的parent和当前样品的parent相同，并且有qctype  代表遍历到的该样品为子样品
            if ((this.testEntryData.sampleBeans[i].parent == sampleObj.parent) && this.testEntryData.sampleBeans[i].qcType != null) {

              for(var m in this.indoorParallel){
                if( this.testEntryData.sampleBeans[i].qcType ===  this.indoorParallel[m]){ //indoorParallel:定义平行子样的个数
                   isPaeall = true;
                   paralNum++;
                }
              }

              for (var j in this.testEntryData.sampleBeans[i].itemBeans) { //遍历子样的检测项

                if (this.testEntryData.sampleBeans[i].itemBeans[j].resultMap.NORM001 !== undefined) {
                  // 子样的所有的检测项的父样结果 的值 为当前样品的对应的检测项的报出结果
                  for (var k in sampleObj.itemBeans) {
                    if (this.testEntryData.sampleBeans[i].itemBeans[j].itemCode == sampleObj.itemBeans[k].itemCode) { // 即子样中检测项（钙）的父样结果 为 父样检测项（钙）的报出结果,根据itemCode匹配

                      //7.1 indoorParallel:单独计算室内平行的报出结果:父样的报出结果 = 父样的报出结果计算值 + 子样的报出结果的平均值，然后和低限判断 然后再修约 2019-08-02
                      if(sampleObj.itemBeans[k].dataType == "DT001"){
                        var  item = this.testEntryData.sampleBeans[i].itemBeans[j]
                        // console.log(this.indoorParallel)
                        // debugger;
                        if(isPaeall && this.stringNotEmpty(item.resultMap.RES001) && this.stringNotEmpty(sampleObj.itemBeans[k].resultMap.RES001)){

                          //7.1.1 原始结果修约
                          // var child = this.decimal(item.decimalRule,item.decimalNumber, item.resultMap.RES001.value); //子样原始结果修约
                          // var par = this.decimal(sampleObj.itemBeans[k].decimalRule, sampleObj.itemBeans[k].decimalNumber, sampleObj.itemBeans[k].resultMap.RES001.value); //将父样原始结果修约
                          
                          // var child = item.resultMap.RES001.value == this.isNd ? 0 : item.resultMap.RES001.value
                          // var par = sampleObj.itemBeans[k].resultMap.RES001.value == this.isNd?0: sampleObj.itemBeans[k].resultMap.RES001.value
                          var child = item.resultMap.RES001.value == this.isNd ? 0 : this.decimal(item.decimalRule,item.decimalNumber, item.resultMap.RES001.value)
                          var par = sampleObj.itemBeans[k].resultMap.RES001.value == this.isNd?0:this.decimal(sampleObj.itemBeans[k].decimalRule, sampleObj.itemBeans[k].decimalNumber, sampleObj.itemBeans[k].resultMap.RES001.value)
                          
                          
                          //7.1.2 得到报出结果的计算结果
                          if(sampleObj.itemBeans[k].low !=null && sampleObj.itemBeans[k].low !='' && Number(par) < Number(sampleObj.itemBeans[k].low)){//若父样的原始结果修约小于下限，则父样报出结果的计算值为 二分之一下限
                              par =  Number(sampleObj.itemBeans[k].low) / 2 ;
                          }
                          if(item.low !=null && item.low !='' && Number(child) < Number(item.low)){
                              child = Number(sampleObj.itemBeans[k].low)/2
                          }
                          if(paralNum == 1){
                              sampleObj.itemBeans[k].totle = Number(par);//累加的初始值为父样
                          }

                          sampleObj.itemBeans[k].totle = Number(sampleObj.itemBeans[k].totle) + Number(child);//累加子样 //在检测项目上放入平行样品的累计值
                          // if(paralNum == 1){
                          //     paral = Number(paral) + Number(par);//累加的初始值为父样
                          // }
                          //  console.log(paral)
                          // paral = Number(paral) + Number(child);//累加子样
                          // console.log(paral)
                          //7.1.3 求平均值(子样的报出结果的计算结果 + 父样的报出结果的计算结果) / 子样加父样的个数  Number(paralNum + 1) 子样加父样的个数
                          sampleObj.itemBeans[k].resultMap.RES002.value = Number( sampleObj.itemBeans[k].totle)/ Number(paralNum + 1);
                          //7.1.4 平均值与下限比较
                          if (sampleObj.itemBeans[k].low != undefined && sampleObj.itemBeans[k].low != null) { //1）只有下限

                            if (sampleObj.itemBeans[k].resultMap.RES002.value < Number(sampleObj.itemBeans[k].low)) {
                              sampleObj.itemBeans[k].resultMap.RES002.value = "<" + sampleObj.itemBeans[k].low; //报出结果显示 <下限
                            }else{ //大于下限在修约
                              //7.1.5 平均值修约
                              sampleObj.itemBeans[k].resultMap.RES002.value = this.decimal(sampleObj.itemBeans[k].decimalRule, sampleObj.itemBeans[k].decimalNumber, sampleObj.itemBeans[k].resultMap.RES002.value);

                            }
                          }else{ //大于下限在修约
                            //7.1.5 平均值修约
                            sampleObj.itemBeans[k].resultMap.RES002.value = this.decimal(sampleObj.itemBeans[k].decimalRule, sampleObj.itemBeans[k].decimalNumber, sampleObj.itemBeans[k].resultMap.RES002.value);
                          }

                        }
                      }

                      // 父样的原始结果不为空的时候才显示子样的父样结果
                      if(sampleObj.itemBeans[k].resultMap.RES001.value !== ""&&sampleObj.itemBeans[k].resultMap.RES001.value !== null){

                        //7.2 子样品的父样结果 = 普通样品的原始结果修约后和下限对比,;要显示在页面的；
                        // var normPar = this.decimal(sampleObj.itemBeans[k].decimalRule,sampleObj.itemBeans[k].decimalNumber, sampleObj.itemBeans[k].resultMap.RES001.value); //父样原始结果修约
                        var normPar = 0;
                        if(sampleObj.itemBeans[k].resultMap.RES001.value != this.isNd){
                            normPar = this.decimal(sampleObj.itemBeans[k].decimalRule,sampleObj.itemBeans[k].decimalNumber, sampleObj.itemBeans[k].resultMap.RES001.value); //父样原始结果修约
                        }
                        // console.log(normPar,sampleObj.itemBeans[k].resultMap.RES002.value)
                        if(sampleObj.itemBeans[k].low !==null && sampleObj.itemBeans[k].low !='' && Number(normPar) < Number(sampleObj.itemBeans[k].low)){
                           normPar = "<" + sampleObj.itemBeans[k].low;
                        }
                        this.testEntryData.sampleBeans[i].itemBeans[j].resultMap.NORM001.value = normPar;  //所有的样品都被赋值为父样的原始结果修约后和下限对比
                      }else{
                        this.testEntryData.sampleBeans[i].itemBeans[j].resultMap.NORM001.value = null;  //所有的样品都被赋值为父样的原始结果修约后和下限对比
                      }
                      //7.3子样的父样原始结果，用来计算相对偏差
                      this.testEntryData.sampleBeans[i].itemBeans[j].resultMap.DEF101 = {value:null};
                      this.testEntryData.sampleBeans[i].itemBeans[j].resultMap.DEF101.value = sampleObj.itemBeans[k].resultMap.RES001.value
                      //7.3子样的父样报出结果，用来计算加标回收率
                      if(this.stringNotEmpty( this.testEntryData.sampleBeans[i].itemBeans[j].resultMap.NORM011) && this.stringNotEmpty( this.testEntryData.sampleBeans[i].itemBeans[j].resultMap.NORM012)){
                        // debugger;
                        this.testEntryData.sampleBeans[i].itemBeans[j].resultMap.DEF102 = {value:null};
                        this.testEntryData.sampleBeans[i].itemBeans[j].resultMap.DEF102.value = sampleObj.itemBeans[k].resultMap.RES002.value

                      }

                    }
                  }
                }
              }
            }
          }

        }

        // 8.计算平均值和相对偏差,NORM001父样结果,NORM002平均值
        // console.log(row.resultMap.NORM001.value)
        if (this.stringNotEmpty(row.resultMap.RES001) && this.stringNotEmpty(row.resultMap.NORM001)) {
          //8.1 如果该项目是数字则计算平均值和相对偏差
          if(row.dataType == 'DT001'){

            if(row.resultMap.DEF101 != undefined){ // DEF101 父样的原始结果
              var child =row.resultMap.RES001.value == this.isNd ? 0:  this.decimal(row.decimalRule, row.decimalNumber, row.resultMap.RES001.value); //原始结果修约
              var par = row.resultMap.DEF101.value == this.isNd ? 0: this.decimal(row.decimalRule, row.decimalNumber, row.resultMap.DEF101.value); //将父样原始结果修约
              if(row.hasAnalysis !== undefined && row.hasAnalysis){ //如果该项目有被标记该样品下有信号分析项，则使用信号分析项的原始结果和父样结果来计算相对偏差
                par = row.parResult;
                child = row.orgResult;
              }
              if(row.low !=null && row.low !='' && Number(par) < Number(row.low)){//若父样的原始结果小于下限，则父样报出结果的计算值为 二分之一下限
                  par =  Number(row.low) / 2 ;
              }
              if(row.low !=null && row.low !='' && Number(child) < Number(row.low)){
                  child = Number(row.low)/2
              }
              //8.1.1 计算平均值 (平均值=（该样品报出结果+父样报出结果）/2  ；修约规则跟项目报出结果一样)
              if (row.resultMap.NORM002 !== undefined) {
                // this.$math.parser().eval

                var add = "(" + Number(child) + "+"+ Number(par) + ")" + "/" + 2
                row.resultMap.NORM002.value = Number(this.$math.parser().eval(add))
                row.resultMap.NORM002.value = this.decimal(row.decimalRule, row.decimalNumber, row.resultMap.NORM002.value);

              }
              //8.1.2 计算相对偏差 (相对偏差=│（该样品报出结果-父样报出结果）│/（该样品报出结果+父样报出结果）*100%，其中││表示绝对值的意思；保留到小数点后两位即可)
              var cha = Number(child) - Number(par);
              if (cha < 0) {
                cha = Number(par) - Number(child);
              }
              var m = Number(Number(child) + Number(par))
              if(m < 0){
                m = Math.abs(m);
              }
              var cha1 = null;
              if (m == 0) { //如果该样品报出结果+父样报出结果为0，判断是互为相反数还是该样品报出结果，父样报出结果都为0
                if (Number(child) == 0 && Number(par) == 0) { //如果都为0  则为100%，互为相反数则为0%
                    cha1 = 0
                } else {
                  cha1 = 1
                }
              } else {
                  cha1 = cha / m; //分母为0
              }
              cha1 = Number(cha1 * 100).toFixed(2);
              if (row.resultMap.NORM003 !== undefined) {
                  row.resultMap.NORM003.value = cha1 + "%";
              }
            }
          }else{ //8.2 如果该项目不是数字 则将平均值和相对偏差设置为 0
            if(row.resultMap.NORM002 != undefined){
              row.resultMap.NORM002.value = 0
            }
            if(row.resultMap.NORM003 != undefined){
              row.resultMap.NORM003.value = 0
            }
          }
        }

        // NORM002 平均值  NORM003相对偏差
        if(row.resultMap.RES002.value == "/" || (this.stringNotEmpty(row.resultMap.NORM001) && row.resultMap.NORM001.value == "/" )){
            if(row.resultMap.NORM002 != undefined){
              row.resultMap.NORM002.value = 0
            }
            if(row.resultMap.NORM003 != undefined){
              row.resultMap.NORM003.value = 0
            }
        }
        // || row.resultMap.NORM001.value == "/"

        // 9.加标回收率=【（该样品报出结果*加标后总体积）-（父样报出结果*取样品体积）】/(加标标样浓度*取标样体积）*100% ；
        // 其中 加标后总体积（NORM004）=取标样体积(NORM011)+取样品体积(NORM012)，回收率结果保留到小数点后一位即可
        // NORM005加标回收率
        if (row.resultMap.NORM005 !== undefined) {
          row.resultMap.NORM005.value = null;
        }
        if (row.resultMap.NORM004 !== undefined) {
          row.resultMap.NORM004.value = null;
        }
        if (this.stringNotEmpty(row.resultMap.NORM011) && this.stringNotEmpty(row.resultMap.NORM012)) {
          if(row.dataType == "DT001"){
            if(row.resultMap.NORM013 == undefined){
              var obj ={value:0};
              this.$set(row.resultMap,'NORM013',obj)
            }

            if(  row.resultMap.NORM013.value == null || row.resultMap.NORM013.value == "" ){
               row.resultMap.NORM013.value = 0
            }
            var sumCap = Number(row.resultMap.NORM011.value) + Number(row.resultMap.NORM012.value) + Number(row.resultMap.NORM013.value); //加标后总体积
            row.resultMap.NORM004.value = sumCap;
            if (this.stringNotEmpty(row.resultMap.RES001) && this.stringNotEmpty(row.resultMap.NORM010) && this.stringNotEmpty(row.resultMap.NORM001)) {
              //9.1 子样的报出结果的计算值：原始结果修约后 与 下限比较，若小于下限则为 0，大于下限则为修约值

              var child = row.resultMap.RES001.value == this.isNd ? 0: this.decimal(row.decimalRule, row.decimalNumber, row.resultMap.RES001.value); //原始结果修约
              if (row.low != undefined && row.low != null) { //1）只有下限
                if (child < Number(row.low)) {
                  child = 0
                }
              }
              // console.log(child,111)
              //9.2 父样的报出结果计算值：两种情况：若有平行样，则计算值为父样的报出结果，若无平行样，则计算值为父样的原始结果修约后与下限比较
              if(row.resultMap.DEF102 != undefined){
                console.log(row,row.resultMap.DEF102)
                var NORM100 = null; //用来替代父样的报出结果计算值
                var NORStr = row.resultMap.DEF102.value.toString(); //先把值转化成字符串
                if(NORStr.indexOf('<') != -1){ //判断是否包含<,包含的话用0 计算
                  NORM100 = 0
                }else{
                  NORM100 = row.resultMap.DEF102.value;
                }
              }
              // console.log(NORM100,222)
              var val = Number(child) * sumCap - Number(NORM100) * Number(row.resultMap.NORM012.value) //【（该样品报出结果*加标后总体积）-（父样报出结果*取样品体积）】
              console.log(Number(NORM100))
              var val2 = Number(row.resultMap.NORM010.value) * Number(row.resultMap.NORM011.value)
              console.log(val,val2)
              var val3 = Number(val / val2 * 100).toFixed(2);
              row.resultMap.NORM005.value = val3 + "%"
              //  console.log(val,val2,333)
            }
            // 如果变成原始结果（报出结果）或者父样报出结果 “/”  加标回收率 为0
            if(row.resultMap.RES002.value == "/" || (this.stringNotEmpty(row.resultMap.NORM001) && row.resultMap.NORM001.value == "/" )){
                  row.resultMap.NORM005.value = 0

            }
          }else{
            if (row.resultMap.NORM005 !== undefined) {
              row.resultMap.NORM005.value = 0;
            }
            if (this.stringNotEmpty(row.resultMap.NORM011) && this.stringNotEmpty(row.resultMap.NORM012) && !isNaN(row.resultMap.NORM011.value) && !isNaN(row.resultMap.NORM012.value)) {
               var sumCap = Number(row.resultMap.NORM011.value) + Number(row.resultMap.NORM012.value); //加标后总体积
              row.resultMap.NORM004.value = sumCap;
            }else{
              row.resultMap.NORM004.value = 0;
            }
          }
        }
      },
      // 计算公式
      countFormula(sampleObj){
        //5.检测项目与分析项目中  - 解析公式并计算
        var tempArr = []; //组装数据:将检测项目与分析项目合并在一个数组中
        tempArr.push(sampleObj);
        var forEachSample = this.concatArr(tempArr) //遍历到的样品下的分析项和检测项的组合
        for (var i in forEachSample) { //遍历所有的分析项目与检测项目 -- 主要用于计算公式
           //4.2）得到新的信号值（原信号值 - 空白信号值）
          if (sampleObj.doStandard == null || !sampleObj.doStandard) { //// 找到曲线分析项，如果点击的样品不为标准样品，找到它的曲线分析项,取itemCode
            // 如果点击的不是标准系列样品，找到信号分析项，信号分析项的值为本身的RES001 - 平均值
            if (forEachSample[i].analysisType == 1) {
              if (forEachSample[i].resultMap.RES001.value != null && forEachSample[i].resultMap.RES001.value != '/' && forEachSample[i].resultMap.RES001.value != this.isNd) {
                var a = forEachSample[i].resultMap.RES001.value - this.blankSum
                forEachSample[i].resultMap.DEF100.value = Number(this.$math.eval(a));
              } else {
                forEachSample[i].resultMap.DEF100.value = forEachSample[i].resultMap.RES001.value
              }
            }
          }
          //将分析项的analysisCode 转化成为 检测项目的itemCode
          forEachSample[i].itemCode = forEachSample[i].analysisCode != null ? forEachSample[i].analysisCode : forEachSample[i].itemCode;
          if (forEachSample[i].formula == null || forEachSample[i].formula == '') { //公式不为空,才继续解析
            continue;
          }
          var arr = forEachSample[i].formula.split(","); //将公式分解为数组
          var codesFlag = 1;
          var isThreeMesh = false;
          // console.log(this.testEntryData.curveBean.slope,this.testEntryData.curveBean.deviation)
          for (var j in arr) { //遍历一个公式的字符，并存储code到 codeArr数组中

            if (arr[j] == "?") { //判断是否是三目运算
              isThreeMesh = true;
            }
            if (arr[j] == "a") { //判断斜率，并赋值
              if (this.testEntryData.curveBean.slope == undefined) {
                codesFlag = codesFlag * 0; //表明没有被替换
              } else {
                arr[j] = this.testEntryData.curveBean.slope + "";
              }
            }
            if (arr[j] == "b") { //判断截距，并赋值
              if (this.testEntryData.curveBean.deviation == undefined) {
                codesFlag = codesFlag * 0; //表明没有被替换
              } else {
                arr[j] = this.testEntryData.curveBean.deviation + "";
              }
            }
            if (arr[j].substr(0, 1) == "#" || arr[j].substr(0, 1) == "{") { //获取检测项目或者分析项的code，并替换为值
              var code = arr[j].replace(/#/g, '');
              code = code.replace(/{/g, '');
              code = code.replace(/}/g, '');
              var f = false; //解析标志
              for (var k in forEachSample) { //遍历所有的分析项目与检测项目，目的是当前所有的code为数值
                forEachSample[k].itemCode = forEachSample[k].analysisCode != null ? forEachSample[k].analysisCode : forEachSample[k].itemCode;
                if (code == forEachSample[k].itemCode) { //取公式中的code和分析项和检测项的itemcode对比，如果分析项和检测项的公式用到失去焦点这一行的code 则根据公式给分析项和检测项赋值
                  f = true;
                  if (forEachSample[k].resultMap.DEF100.value == "/") { //如果公式里面有‘/’,公式的结果就为 /
                    codesFlag = codesFlag * 0; //表明没有被替换
                    forEachSample[i].resultMap.RES001.value = '/';
                    forEachSample[i].resultMap.RES002.value = '/';
                    continue;
                  } else if (forEachSample[k].resultMap.DEF100.value == this.isNd) { //如果公式里面有‘ND’,公式的结果就为 ND
                    codesFlag = codesFlag * 0; //表明没有被替换

                    forEachSample[i].resultMap.RES001.value = this.isNd;
                    forEachSample[i].resultMap.RES002.value = this.isNd;
                    continue;
                  }else if (forEachSample[k].resultMap.DEF100.value !== null && forEachSample[k].resultMap.DEF100.value !== "") { //公式被解析计算 是有效的数字
                    codesFlag = codesFlag * 1; //表明被替换
                    arr[j] = forEachSample[k].resultMap.DEF100.value; // ----------
                  }else { //该code已经被找到，但是是没有填值的情况

                    forEachSample[i].resultMap.RES001.value = null;
                    forEachSample[i].resultMap.RES002.value = null;
                    codesFlag = codesFlag * 0; //表明没有被替换
                  }
                }
              }
              if (!f && this.showFaulmCount) {
                this.$notify({
                  title: "警告",
                  message: '公式无法正确解析,请到技术标准检查公式!',
                  type: "warning"
                })
                this.showFaulmCount = false;
                return;
              }
            }

          }
          console.log(codesFlag,'FFFF')
          if (codesFlag == 1) { //表明该检测项目或者分析项的code已经被全部替换成功
            var formu = null;
            if (isThreeMesh) { //判断三目运算符号 A == B ? C :D
              var a = null,
                b = null,
                c = null;
              for (var k in arr) {
                if (arr[k] == "==") { //==的位置
                  a = k;
                }
                if (arr[k] == "?") { //?的位置
                  b = k;
                }
                if (arr[k] == ":") { //:的位置
                  c = k;
                }
              }
              var A = arr.slice(0, a);
              var aa = eval(A.join().replace(/,/g, ''));
              var B = arr.slice(Number(a) + 1, b);
              var bb = eval(B.join().replace(/,/g, ''));
              var C = []; //最终的计算公式
              if (aa == bb) {
                C = arr.slice(Number(b) + 1, c);

              } else {
                C = arr.slice(Number(c) + 1, arr.length);
              }
              formu = C.join().replace(/,/g, '');
            } else {
              //将已经完全替换公式数组转为字符串,带入eval()计算
              formu = arr.join().replace(/,/g, '');

            }
            var num = Number(this.$math.parser().eval(formu)); //把公式计算位数字
            // console.log(formu)
            // 判断计算后的公式是否是小数，如果是整数 直接赋值，如果是小数，判断小数点后位数 如果大于6位则保留6位，小于6位则全部保留
            var result = (num.toString()).indexOf(".");
            var lastResult = Number(this.$math.parser().eval(formu));
            if(result != -1) { //含有小数点并且小数点后大于6位
              if(num.toString().split(".")[1].length > 6){
                lastResult = num.toFixed(6)
              }
            }
            forEachSample[i].resultMap.RES001.value = lastResult;

            forEachSample[i].resultMap.RES002.value = this.decimal(forEachSample[i].decimalRule, forEachSample[i].decimalNumber, forEachSample[i].resultMap.RES001.value);
            // 根据算出的RES001  和修约规则计算报出结果
            if (forEachSample[i].low != undefined && forEachSample[i].low != null) { //1）只有下限
              if (forEachSample[i].resultMap.RES001.value < Number(forEachSample[i].low)) {
                forEachSample[i].resultMap.RES002.value = "<" + forEachSample[i].low; //报出结果显示 <下限
              }
            }
            if ((forEachSample[i].low == undefined || forEachSample[i].low == null) && (forEachSample[i].detectionLimit != undefined && forEachSample[i].detectionLimit != null)) { //2）只有检出限
              if (forEachSample[i].resultMap.RES001.value < Number(forEachSample[i].detectionLimit)) {
                forEachSample[i].resultMap.RES002.value = "<" + forEachSample[i].detectionLimit; // 报出结果显示 < 检出限
              }
            }
          } else if(forEachSample[i].resultMap.RES001.value == '/'){ //儅公式替換不成功的時候，顯示為null
            // forEachSample[i].resultMap.RES001.value = forEachSample[i].resultMap.RES001.value == '/' ? '/' : null;
            // forEachSample[i].resultMap.RES002.value = forEachSample[i].resultMap.RES001.value == '/' ? '/' : null;
            forEachSample[i].resultMap.RES001.value ='/';
            forEachSample[i].resultMap.RES002.value ='/';
          }else{
            console.log(forEachSample[i].resultMap.RES001.value)

            forEachSample[i].resultMap.RES001.value = forEachSample[i].resultMap.RES001.value == this.isNd ? this.isNd : null;

            forEachSample[i].resultMap.RES002.value = forEachSample[i].resultMap.RES001.value == this.isNd ? this.isNd: null;
            if(forEachSample[i].resultMap.RES002.value  == this.isNd &&( forEachSample[i].low != undefined && forEachSample[i].low != null) ){
              forEachSample[i].resultMap.RES002.value = "<" + forEachSample[i].low
            }
          }
        }
      },

      //修约计算:style 编码，number 保留位数，value 数字
      decimal(style, number, value) {
        // debugger;
        if (value === null || value === "") { //如果RES001为null，RES001为空

          return null;
        }

        if (value == "/") {
          return value;
        }
        if (isNaN(value)) {
          return value;
        }
        var name = null;
        number = (number == null) ? 2 : number; //如果保留位数为空，默认两位
        for (var i in this.ruleSelect.itemList) { //把修约规则的值转换成label
          var r = this.ruleSelect.itemList[i].code;
          if (style == r) {
            name = this.ruleSelect.itemList[i].name;
            break;
          }
        }
        if (name == 'ISO') { //四舍五入方法
          return Number(value).toFixed(number);
        }
        if (name == 'EPA') { //保留有效位数 -- 四舍五入 （待优化）
          number = (number == 0) ? 1 : number;
          var v = Number(value).toPrecision(number);
          return new Number(v);
        }
        if (name == 'FDA') { //针对小数点后面：四舍六入五成双
          return this.evenRound(value, number);
        }
        if (name == null) {
          if (!isNaN(value) && value !== "" && value !== null) { //如果是数值型
            return Number(value).toFixed(number)
          } else { //不是数字的话返回当前值
            return value
          }
        }

      },
      //针对小数点后面：四舍六入五成双
      evenRound(value, number) {

        var d = number || 0;
        var m = Math.pow(10, d);
        var n = Number(+(d ? value * m : value)).toFixed(8); // Avoid rounding errors
        var i = Math.floor(n),
          f = n - i;
        var e = 1e-8; // Allow for rounding errors in f
        var r = (f > 0.5 - e && f < 0.5 + e) ?
          ((i % 2 == 0) ? i : i + 1) : Math.round(n);
        var res = d ? r / m : r;
        //  console.log(res)
        res = res.toFixed(number);
        return res;
      },
      //针对有效位数后面：四舍六入五成双
      evenRoundTwo(num, precision) {
        var dnum = Math.pow(10, precision);
        if (Math.floor(num * dnum * 10) % 5 == 0 && Math.floor(num * dnum * 10) == num * dnum * 10 && Math.floor(num *
            dnum) % 2 == 0) {
          return Math.floor(num * dnum) / dnum;
        } else {
          return Math.round(num, precision);
        }
      },

      stringNotEmpty(str) {

        if (str !== undefined && str.value !== null && str.value !== '' && str.value !== '/') {
          return true;
        } else {
          return false;
        }
      },
      seriesData() {
        var flag = false;
        var signalArr = Object.keys(this.signalObj); //把this.signalObj转为数组
        var len = signalArr.length; //取数组的长度,如果两个曲线分析项有值了 调用曲线斜率接口
        if (this.standardArr.length != len) { //信号值没有填写完全；或者信号值为“/”的标准样品太多，不足以生成斜率
          this.$notify({
            message: "缺少标准系列样品信号值",
            type: "wraning",
            title: "警告"
          })
          flag = true;
        }
        return flag;
      },
      // 提交检测单的数据录入

      submitEntery(val) {
        // this.enterFlag = !this.enterFlag
        this.testEntryData.submitType = this.submitType.submitOpen;
        var successMsg = "提交成功!"
        // this.testEntryData.moduleId = this.receptModuleId;
        // this.testEntryData.operation = 'check';
        // clearInterval(this.setIntervalTimes) //点击提交清除定时保存

        if (this.standardArr.length < 2) { //如果该批次不足两个标准系列 则不能提交标准系列以及 斜率等信息
          // this.testEntryData.curveBean = {};
          this.testEntryData.curveBean.hasCriterion = false; // 是否有标准曲线
          this.testEntryData.seriesBeans = [];
        };
        this.isRepeat = false;

        this.$http({
          method: 'post',
          apiUrl: '/detection/modResultData.htm',
          params: this.testEntryData,
          isJson: true
        }).then(res => {
          this.isRepeat = true;
          if (res.code == 0) {
            this.$notify({
              type: 'success',
              title: '成功',
              message: successMsg,
            })
            if (val == 'commit') {
              this.saveErrorQcData(this.testEntryData)
            }
            // this.addOriginal();
            // 提交成功之后刷新页面，调用父函数
            this.$parent.getTestBatchs(this.$parent.testItemQuery)
            this.close();

          }
        })
      },
      // 原始记录相关 审核成功调用
      addOriginal() {
        this.$http({
          method: 'post',
          apiUrl: "/original/addOriginal.htm",
          params: this.testEntryData,
          isJson: true,
        }).then(res => {
          if (res.code == 0) {

          }
        })
      },
      saveErrorQcData(data) {
        this.$http({
          method: 'post',
          apiUrl: '/detection/saveErrorQcData.htm',
          params: data,
          isJson: true
        }).then(res => {

        })
      },
      // 仪器使用前检查项
      lookequipCheck() {
        if (this.testEntryData.equipment == null) {
          this.$notify({
            title: '警告',
            message: '找不到仪器',
            type: 'warning'
          })
        } else if (!this.testEntryData.hasEquipUse) {
          this.$notify({
            title: '警告',
            message: '无仪器使用记录',
            type: 'warning'
          })
        } else {
          this.equipCheckShow = true;
        }
      },
      // 分析项和检测项目选中的值
      handleSelectionChange(val) {
        this.multipleSelection = val;
        this.$set(this.multipleSelections, this.multipleSelecInd, val);
        var arr = this.multipleSelections.filter(item => item.length != 0) //过滤掉长度为0的数组
        this.multipleSelectionsLen = arr.length;
      },
      // 批录入功能开始   选中某个样品的分析项或者检测项，录入值后点击“批录入”，
      // 那么该批次中的所有样品的同名分析项或者检测项的空的属性都是该值
      batchInput() {
        if (this.multipleSelection.length > 1) { // 如果勾选的条数大于1条的提示
          this.$message({
            type: 'info',
            message: '请只选中一条数据检测项或者分析项！'
          })
        } else {
          // this.$confirm('是否批录入', '提示', {
          //     confirmButtonText: '确定',
          //     cancelButtonText: '取消',
          //     type: 'warning'
          // }).then(() => {
          // 判断勾选的这一条是分析项还是检测项，取该条的分析项或者检测项id对比
          var selectAnalysisOrItem = null
          if (this.multipleSelection[0].analysis != undefined) {
            selectAnalysisOrItem = this.multipleSelection[0].analysis
          } else {
            selectAnalysisOrItem = this.multipleSelection[0].item
          }
          // 把该批次下所有样品的检测项和分析项合并为一个数组tempArr
          var tempArr = [];
          for (var i in this.testEntryData.sampleBeans) {
            for (var j in this.testEntryData.sampleBeans[i].analysisBeans) {
              tempArr.unshift(this.testEntryData.sampleBeans[i].analysisBeans[j]);
            }
            for (var j in this.testEntryData.sampleBeans[i].itemBeans) {
              tempArr.push(this.testEntryData.sampleBeans[i].itemBeans[j]);
            }
            this.reLoad()
          }
          // 遍历所有样品下的分析项和检测项,
          // 1.判断tempArr的每条数据是检测项目还是分析项，把id存为allAnalysisOrItem
          // 2.把allAnalysisOrItem和勾选的一条数据的检测项目或者分析项的id对比，如果相同，该条数据下空的属性和勾选的数据设置为相同
          var allAnalysisOrItem = null;
          for (var i in tempArr) {
            if (tempArr[i].analysis != undefined) { //如果该条有analysis，既该条是分析项否则是检测项
              allAnalysisOrItem = tempArr[i].analysis
              if (tempArr[i].analysis == selectAnalysisOrItem) {
                for (var j in this.multipleSelection[0].resultMap) {
                  if (tempArr[i].resultMap[j] !== undefined) {
                    if (tempArr[i].resultMap[j].value == '' || tempArr[i].resultMap[j].value == null) {
                      tempArr[i].resultMap[j].value = this.multipleSelection[0].resultMap[j].value
                    }
                  }
                }
              }
            } else {
              allAnalysisOrItem = tempArr[i].item
              if (tempArr[i].item == selectAnalysisOrItem) {
                for (var j in this.multipleSelection[0].resultMap) {
                  if (tempArr[i].resultMap[j] !== undefined) {
                    if (tempArr[i].resultMap[j].value == "" || tempArr[i].resultMap[j].value == null) {
                      tempArr[i].resultMap[j].value = this.multipleSelection[0].resultMap[j].value
                    }
                  }
                }
              }
            }
          }
          this.enterFlag = !this.enterFlag
          this.multipleSelections.length = 0;
          this.multipleSelections = [];
          this.multipleSelectionsLen = 0
          this.$refs.sampleTable.clearSelection();
          // })
        }
      },
      // 选中的样品
      handleSampleChange(val) {
        this.sampleSelection = val

      },
      // 无效结果弹框
      resultVoid() {
        this.resultVoidShow = true;
      },
      // 初始化
      initResult() {
        var that = this;
        this.$confirm('是否初始化', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {

          for (var i in this.sampleSelection) { //初始化时 所有列变为null 再重新赋值
            for (var j in this.sampleSelection[i].itemBeans) { //检测项的方法检出限 值为 检测项的detectionLimit,检测项的单位RES003值为unitName

              for (var k in this.sampleSelection[i].itemBeans[j].resultMap) {
                this.sampleSelection[i].itemBeans[j].resultMap[k].value = null;
              }
              // 检测项的方法检出限默认为detectionLimit
              this.sampleSelection[i].itemBeans[j].resultMap.RES004.value = this.sampleSelection[i].itemBeans[j].low;
              this.sampleSelection[i].itemBeans[j].resultMap.RES003.value = this.sampleSelection[i].itemBeans[j].unitName;

            }
            for (var j in this.sampleSelection[i].analysisBeans) { //分析项的单位RES003值为unitName
              for (var k in this.sampleSelection[i].analysisBeans[j].resultMap) {
                this.sampleSelection[i].analysisBeans[j].resultMap[k].value = null;
              }
              //分析项的原始结果是该分析的默认值
              this.sampleSelection[i].analysisBeans[j].resultMap.DEF100.value = null;
              this.sampleSelection[i].analysisBeans[j].resultMap.RES001.value = this.sampleSelection[i].analysisBeans[
                j].defaultValue;
              this.sampleSelection[i].analysisBeans[j].resultMap.RES002.value = this.decimal(this.sampleSelection[i]
                .analysisBeans[j].decimalRule, this.sampleSelection[i].analysisBeans[j].decimalNumber, this.sampleSelection[
                  i].analysisBeans[j].resultMap.RES001.value)
              this.testEntryData.curveBean.slope = null //a,b清空重新计算
              this.testEntryData.curveBean.deviation = null
              this.testEntryData.curveBean.coefficent = null;
              this.sampleSelection[i].analysisBeans[j].resultMap.RES003.value = this.sampleSelection[i].analysisBeans[
                j].unitName;
            }
            // 如果是标准系列样品
            if (this.sampleSelection[i].doStandard) {
              //1）获取标准系列样品的名字截取std，并为每个分析项加一个std属性--值为std1....
              var std = this.sampleSelection[i].sampleName.replace(/标准系列/g, ''); //改样品的std
              this.standardArr.push(this.sampleSelection[i])
              for (var j in this.sampleSelection[i].analysisBeans) {
                if (this.sampleSelection[i].analysisBeans[j].resultMap.NORM006 !== undefined) {
                  this.sampleSelection[i].analysisBeans[j].std = std;
                  //2）获取标准系列样品中分析项的信号值
                  if (this.sampleSelection[i].analysisBeans[j].analysisType == 1) {
                    // 3）获取标准系列样品中的曲线分析项，和seriesBeans对比，如果曲线分析项的std和seriesBeans的seriesSort相同
                    //标准系列样品中的曲线分析项的标准系列浓度值为相同这一条的seriesConcen
                    for (var k in this.testEntryData.seriesBeans) {
                      if (this.testEntryData.seriesBeans[k].seriesSort == std) {
                        this.sampleSelection[i].analysisBeans[j].resultMap.NORM006.value = this.testEntryData.seriesBeans[
                          k].seriesConcen
                      }
                    }
                  }
                }
              }
            }
          }
          this.enterFlag = !this.enterFlag
          this.multipleSelections.length = 0;
          this.multipleSelections = [];
          this.multipleSelectionsLen = 0
          this.$refs.sampleTable.clearSelection();

        }).catch(() => {
          // flag = false;
          this.$message({
            type: 'info',
            message: '已取消'
          });
        });
      },
      // 把检测项和分析项合并为一个数组tempArr
      concatArr(arr) {
        var tempArr = []
        for (var i in arr) {
          for (var j in arr[i].analysisBeans) {
            tempArr.push(arr[i].analysisBeans[j]);
          }
          for (var j in arr[i].itemBeans) {
            tempArr.push(arr[i].itemBeans[j]);
          }
        }

        return tempArr;
      },
      // 关闭无效结果原因弹框,清空结果
      closeResultVoid() {
        this.resultVoidShow = false;
        this.resultVoidValue = null;
      },
      // 提交选中的无效结果原因
      subResultVoid() {
        if (this.resultVoidValue == null) {
          this.$message({
            type: 'info',
            message: '请先选中无效结果的原因!'
          })
        } else {
          // 问题  同一个样品下的检测项和分析项的resultMap 不一样
          var beans = [];
          beans = this.concatArr(this.sampleSelection)
          for (var i in beans) {
            beans[i].valueStyle = this.resultVoidValue;
            beans[i].resultMap.RES001.value = "/"
            beans[i].resultMap.RES002.value = "/"
            beans[i].resultMap.DEF100.value = '/'
            // if(beans[i].resultMap.NORM005 != undefined){
            //   console.log(beans[i].resultMap.NORM005)
            //   beans[i].resultMap.NORM005.value = '/'
            // }
          }
          this.closeResultVoid();
          this.reLoad();
          this.$refs.sampleTable.clearSelection();
          this.enterFlag = !this.enterFlag
        }

      },
      finshed() { //强制完成
        // this.resultVoidValue; 5
        // this.$confirm('是否强制完成', '提示', {
        //     confirmButtonText: '确定',
        //     cancelButtonText: '取消',
        //     type: 'warning'
        // }).then(() => {
        // this.multipleSelections [0:[],1:[],3:[]]
        for (var i in this.multipleSelections) { //this.multipleSelections[0]
          for (var j in this.multipleSelections[i]) {
            for (var k in this.multipleSelections[i][j].resultMap) {
              this.multipleSelections[i][j].valueStyle = 5;
              // this.multipleSelections[i][j].resultMap[k] = '/'
              this.multipleSelections[i][j].resultMap.RES001.value = '/'
              this.multipleSelections[i][j].resultMap.RES002.value = '/'
              this.multipleSelections[i][j].resultMap.DEF100.value = '/'
            }
          }
        }
        this.multipleSelections.length = 0;
        this.multipleSelections = [];
        this.multipleSelectionsLen = 0

        this.$refs.fenxixiangTable.clearSelection(); //取消的当前列表勾选
        this.enterFlag = !this.enterFlag
        // }).catch(() => {
        //     this.$message({
        //         type: 'info',
        //         message: '已取消'
        //     });
        // });

      },
      toggleSelection1(row) { //点击样品 左边选中状态
        //默认选中状态
        var that = this;
        row = row || [];
        row.forEach(arr => {
          that.$refs.fenxixiangTable.toggleRowSelection(arr);
        });
      },

      // 取消样品勾选
      toggleSelection(rows) {
        if (rows) {
          rows.forEach(row => {
            this.$refs.sampleTable.toggleRowSelection(row);
          });
        } else {
          this.$refs.sampleTable.clearSelection();
        }
      },
      // 标准曲线,查看最新
      standarLine() {
        this.$http({
          method: 'post',
          apiUrl: '/detection/readCriterion.htm',
          params: {
            batch: this.testEntryData.id
          },
          isJson: false,
        }).then(res => {
          if (res.code === 0) {
            if (res.data == undefined) {
              this.$notify({
                message: "本批次未应用新的标准曲线,将自动应用默认曲线！",
                title: "警告",
                type: "warning"
              });
              return;
            }
            this.standardseriesshow = true;
            this.standardSeriesForm = res.data;

          }
        })
      },
      //将信号值以及浓度值组装成为合适的方式用于计算斜率与截距
      makeCoefficientData(signalObj) { //signalObj 就是公共变量 this.signalObj 是标准系列样品的曲线参数的报出结果值组成的对象 {std1:'',std2:""}

        // if (row.resultMap.RES001 != null && row.resultMap.RES001 != undefined && row.resultMap.RES001 != '' && !isNaN(row.resultMap.RES001))
        var xy = {};
        var x = [],
          y = [];
        for (var i in this.testEntryData.seriesBeans) { //遍历标准系列值，取标准系列浓度 作为点的x轴,录入的值为y轴值
          // signalObj里面std得值不是 / 和 null undefined 和 '',并且不是字符串得时候加入坐标
          // debugger
          if (signalObj[this.testEntryData.seriesBeans[i].seriesSort] != '/' && signalObj[this.testEntryData.seriesBeans[
              i].seriesSort] != undefined && signalObj[this.testEntryData.seriesBeans[i].seriesSort] !== '' &&
            signalObj[this.testEntryData.seriesBeans[i].seriesSort] != null && !isNaN(signalObj[this.testEntryData.seriesBeans[
              i].seriesSort])) {
            x.push(Number(this.testEntryData.seriesBeans[i].seriesConcen));
            y.push(Number(signalObj[this.testEntryData.seriesBeans[i].seriesSort]));
            this.testEntryData.seriesBeans[i].signal = Number(signalObj[this.testEntryData.seriesBeans[i].seriesSort])
          }
        }
        xy.x = x;
        xy.y = y;
        return xy;
      },
      //计算斜率和截距
      getCoefficient(x1, y1) {
        var that = this;
        if (x1.length < 2 || y1.length < 2) {
          return;
        }
        // 标准系列样品曲线计算方式
        var x = x1;
        var y = y1;
        // debugger;
        if (x.length > 0) {
          if (this.testEntryData.mustZone) {

            var y0 = y[0]
            for (var j in y) {
              y[j] = y[j] - y0;
            }
          }
        }
        var data = [];
        var xy = {
          x: x1,
          y: y1
        }
        this.$commitHttp(process.env.baseUrl + 'detection/getCoefficient.htm', JSON.stringify(xy), {
          success: function(res) {

            //根据截距与斜率计算两个点位
            that.testEntryData.curveBean = {};
            that.testEntryData.curveBean.detectability = that.testEntryData.detectability;
            that.testEntryData.curveBean.equipment = that.testEntryData.equipment;
            that.testEntryData.curveBean.slope = res.data.slope.toFixed(4);
            that.testEntryData.curveBean.deviation = res.data.deviation.toFixed(4);
            that.testEntryData.curveBean.coefficent = res.data.coefficent.toFixed(4);
            that.testEntryData.curveBean.criterion = that.testEntryData.seriesBeans[0].criterion;
            that.testEntryData.curveBean.batch = that.testEntryData.sampleBeans[0].batch;
          }
        }, false);

      },
      // 提交改批次的斜率截距和点位
      addCriterionSeries() {
        this.$http({
          method: 'post',
          apiUrl: '/detection/addCriterionSeries.htm',
          params: this.testEntryData,
          isJson: true
        }).then(res => {
          if (res.code == 0) {

          }
        })
      },

      // 关闭弹框，清空数据
      close() {
        this.$emit('update:addVisible', false);
        this.isRepeat = true;
        this.yuanshijiemian = true; //切换视图重置为原始值
        this.resultTableData = [];
        this.standardArr = [];
        this.signalObj = {};
        this.multipleSelections = []
        this.sampleAndItemSelection = [];
        this.allItemAndAnalysis = [];
        this.resultTableTitle = [];
        this.isSuccess = true;
        this.loading1 = true;
        this.clickSample = {};
         this.$emit('update:selectData', {});
          this.testEntryData = {}
        clearInterval(this.setIntervalTimes)
      },
      //切换视图
      changeView() {
        // this.enterFlag = !this.enterFlag
        this.sampleSelection = [];
        this.multipleSelections.length = 0;
        this.multipleSelections = [];
        this.multipleSelection = [];
        this.multipleSelectionsLen = 0;
        this.yuanshijiemian = !this.yuanshijiemian
      },

      // 根据行属性,设置行样式
      rowStyle({
        row,
        rowIndex
      }) {
        if (row.color == '1') {
          return 'color:rgb(73, 204, 123)'
        } else if (row.color == '2' || row.color == '3') {
          return 'color:#5fb2e3'
        }
      },
      resultTableCurrentChange(val) {
        this.resultTableCurrent = val;
      },
      // 上传附件按钮
      uploadAttachment() {
        document.getElementById("attachment").click()
      },
      attachment(event) {
        var files = document.getElementById('attachment').files
        if (files == undefined) {
          return;
        }
        var formData = new FormData();
        for (var i of files) {
          formData.append('file', i)
        }
        // formData.append('file', files)
        formData.append('ids', this.testEntryData.id)
        formData.append('type', 3)
        formData.append('taskType', null)
        formData.append('detectability', null)
        formData.append('fileType', 'batch')
        this.$axios({
          method: 'post',
          url: '/download/fileUpload.htm',
          data: formData,
          headers: {
            'Content-Type': 'multipart/form-data',
            'token':sessionStorage.getItem('loginAccount')?sessionStorage.getItem('loginAccount'):undefined
          }
        }).then(res => {
          event.target.value = "";
          var data = res.data
          if (data.code == 0) {
            this.$notify({
              title: '消息',
              message: '上传成功',
              type: 'success'
            })
          } else {
            this.$message({
              type: 'info',
              message: data.description,
            })
          }

        })
      },

      // 上传结果按钮
      uploadClick() { // 模拟file的点击事件
        document.getElementById("file").click()
      },
      // 上传结果
      upload(event) {
        this.loading = true;
        var files = document.getElementById('file').files[0];
        if (files == undefined) {
          this.loading = false;
          return;
        }
        var formData = new FormData();
        formData.append('eId', this.testEntryData.equipment);
        formData.append('uploadFile', files)

        this.$axios({
          method: 'post',
          url: '/detection/manualParsing.htm',
          data: formData,
          headers: {
            'Content-Type': 'multipart/form-data',
            'token':sessionStorage.getItem('loginAccount')?sessionStorage.getItem('loginAccount'):undefined
          }
        }).then(res => {
          this.loading = false;
          event.target.value = "";
          var data = res.data
          if (data.code == 0) {
            this.$notify({
              title: '消息',
              message: '获取数据成功',
              type: 'success'
            })
            this.randerData(res.data.data)

          } else {
            this.$notify({
              title: '消息',
              type: 'warning',
              message: data.description,
            })
          }

        })
      },
      randerData(data) { //上传结果成功后 把接口返回的数据渲染再检测项和分析项的表  根据返回sample和样品的

        for (var i in data) { //遍历上传成功返回的数据
          for (var j in this.testEntryData.sampleBeans) { //遍历样品
            if (data[i].sample == this.testEntryData.sampleBeans[j].sampleCode) { //如果返回数据中的sample和样品的sample相等，合并该样品的检测项和分析项
              var tempArr = [];
              for (var k in this.testEntryData.sampleBeans[j].analysisBeans) {
                //把分析项的analysisCode转为itemCode
                this.testEntryData.sampleBeans[j].analysisBeans[k].itemName = this.testEntryData.sampleBeans[j].analysisBeans[
                  k].analysisName
                tempArr.unshift(this.testEntryData.sampleBeans[j].analysisBeans[k]);
              }
              for (var k in this.testEntryData.sampleBeans[j].itemBeans) {
                tempArr.push(this.testEntryData.sampleBeans[j].itemBeans[k]);
              }
              for (var k in tempArr) { //遍历检测项和分析项

                if (data[i].item == tempArr[k].itemName) { //如果遍历到的数据的item和检测项或分析项的itemCode相同，则把这条数据的值赋给RES001

                  tempArr[k].resultMap.RES001.value = data[i].value;
                }
              }

            }
          }

        }
        this.enterFlag = !this.enterFlag
      },
      // 导出模板
      excelTemplet() {
        var url = "detection/batchExcelTemplet.htm";
        var id = this.testEntryData.id
        let token = sessionStorage.getItem('loginAccount')?sessionStorage.getItem('loginAccount'):undefined
        window.open(process.env.baseUrl + url + '?batch=' + id  + "&token=" + token)
      },
      // 导入结果按钮
      uploadClick1() { // 模拟file的点击事件
        document.getElementById("file1").click()
      },
      // 导入文件
      upload1(event) {
        this.loading = true;
        var files = document.getElementById('file1').files[0];
        if (files == undefined) {
          this.loading = false;
          return;
        }
        var formData = new FormData();
        formData.append('file', files)
        this.$axios({
          method: 'post',
          url: '/detection/readBatchData.htm',
          data: formData,
          headers: {
            'Content-Type': 'multipart/form-data',
            'token':sessionStorage.getItem('loginAccount')?sessionStorage.getItem('loginAccount'):undefined
          }
        }).then(res => {
          this.loading = false;
          event.target.value = "";
          if (res.data.code == 0) {
            this.$notify({
              title: '消息',
              message: '获取数据成功',
              type: 'success'
            })
            this.handleData(res.data.data);

          } else {
            this.$notify({
              title: '消息',
              type: 'warning',
              message: res.data.description,
            })
          }

        })
      },
      // 导入数据成功后
      handleData(data) {
        for (var i in data) {
          for (var j in this.testEntryData.sampleBeans) {
            if (data[i].sampleCode == this.testEntryData.sampleBeans[j].sampleCode) {
              for (var m in data[i].analysList) {
                for (var n in this.testEntryData.sampleBeans[j].analysisBeans) {
                  if (data[i].analysList[m].analysisName == this.testEntryData.sampleBeans[j].analysisBeans[n].analysisName) {
                    this.testEntryData.sampleBeans[j].analysisBeans[n].resultMap.RES001.value = data[i].analysList[m].value;
                  }
                }
                for (var n in this.testEntryData.sampleBeans[j].itemBeans) {
                  if (data[i].analysList[m].analysisName == this.testEntryData.sampleBeans[j].itemBeans[n].itemName) {
                    this.testEntryData.sampleBeans[j].itemBeans[n].resultMap.RES001.value = data[i].analysList[m].value;
                  }
                }
              }
            }
          }
        }
        this.enterFlag = !this.enterFlag
      },
      // 标定结果的表头表头数据
      titrationResult() {
        this.titrationShow = true;
      },
      getCalib() {
        var data = {
          batch: this.testEntryData.id,
        }
        this.$http({
          method: 'post',
          apiUrl: '/detection/getCalib.htm',
          params: data,
          isJson: true,
        }).then(res => {
          if (res.code === 0) {
            if (res.data == undefined) {
              this.titrationBtn = false;
            } else {
              this.titrationData = res.data;
              this.titrationBtn = true;
            }
          }
        })
      },
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->

<style scoped>

</style>
<style>
  .editpanelPop .radioGroup .el-radio {
    margin-left: 30px;
    display: block;
    height: 35px;
    line-height: 35px;
  }

  .editpanelPop .el-input-number.el-input-number--mini {
    width: 100%;
  }

  .editpanelPop .el-input-number.el-input-number--mini input {
    padding: 0 5px;
  }

  .editpanelPop .el-input-number.el-input-number--mini .el-input-number__increase,
  .editpanelPop .el-input-number.el-input-number--mini .el-input-number__decrease {
    display: none;
  }

  .resultVoidDialog .el-dialog {
    margin-top: 26vh !important;
  }

  .resultVoidDialog .el-dialog .el-dialog__header {
    padding: 10px;
    border: none;
  }

  .resultVoidDialog .el-dialog .el-dialog__body {
    padding: 10px;
  }

  #file,
  #attachmentForm,
  #file1 {
    width: 50px;
    height: 20px;
    opacity: 0;
    position: absolute;
    left: 0;
    top: 0;
    z-index: -1;
  }
</style>
